Skip to content

Commit

Permalink
Add --class
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweber committed Jan 13, 2024
1 parent 9033c44 commit 97eb6e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui
#### Options:

> -b, --background
> changes the default behaviour: if the specified program is not running, launch it in the background instead of in the foreground. Thereafter 'hdrop -b' will work the same as without this flag.
> Changes the default behaviour: if the specified program is not running, launch it in the background instead of in the foreground. Thereafter 'hdrop -b' will work the same as without this flag.
>
> -c, --class
> Set classname of the program to be run. Use this if the classname is different from the name of the [COMMAND].
>
> -i, --insensitive
> Case insensitive partial matching of class names. Can work as a stopgap if a running program is not recognized and a new instance is launched instead. Note: incorrect matches may occur, adding a special handling of the program to hdrop is preferable.
Expand All @@ -36,8 +39,8 @@ This Bash script emulates the main features of [tdrop](https://github.com/noctui

Multiple instances of the same program can be run concurrently, if different class names are assigned to each instance. Presently there is support for the following flags in the [COMMAND] string:

> -a ([foot](https://codeberg.org/dnkl/foot/) terminal emulator)
> --class (all other programs)
> `-a` ([foot](https://codeberg.org/dnkl/foot/) terminal emulator)
> `--class` (all other programs)
#### Example bindings in Hyprland config:

Expand Down
31 changes: 26 additions & 5 deletions hdrop
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ print_help() {
echo " not running, launch it in the background instead of foreground."
echo " Thereafter 'hdrop -b' will work the same as without this flag."
echo ""
echo " -c, --class"
echo " Set classname of the program to be run. Use this if the"
echo " classname is different from the name of the [COMMAND]."
echo ""
echo " -i, --insensitive"
echo " Case insensitive partial matching of class names."
echo " Try this if a running program is not recognized and a new"
echo " instance is launched instead."
echo " You can try this if a running program is not recognized and"
echo " a new instance is launched instead."
echo ""
echo " -v, --verbose"
echo " Show notifications regarding the matching process."
Expand All @@ -41,7 +45,7 @@ print_help() {
}

print_version() {
echo "hdrop version: 0.3.0"
echo "hdrop version: 0.3.1"
}

notify() {
Expand Down Expand Up @@ -69,6 +73,10 @@ hdrop_flags() {
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
shift
;;
-c | --class)
CLASS_OVERRIDE="$2"
shift 2
;;
-i | --insensitive)
INSENSITIVE=true
shift
Expand All @@ -95,16 +103,21 @@ while true; do
HDROP_FLAGS+=("$1")
shift
;;
*) break ;;
*)
HDROP_FLAGS+=("$2")
break
;;
esac
done

BACKGROUND=""
INSENSITIVE=false
VERBOSE=false

# shellcheck disable=SC2128
if [[ -n $HDROP_FLAGS ]]; then
hdrop_flags $(getopt --options bivVh --longoptions background,insensitive,verbose,version,help -n hdrop -- "${HDROP_FLAGS[@]}")
# shellcheck disable=SC2046
hdrop_flags $(getopt --options bc:ivVh --longoptions background,class:,insensitive,verbose,version,help -n hdrop -- "${HDROP_FLAGS[@]}")
fi

CLASS="$1"
Expand All @@ -117,9 +130,11 @@ foot)
;;
logseq)
CLASS="Logseq"
if $VERBOSE; then notify_low "hdrop: Using '$CLASS' as hardcoded classname of '$1' for matching"; fi
;;
telegram-desktop)
CLASS="org.telegram.desktop"
if $VERBOSE; then notify_low "hdrop: Using '$CLASS' as hardcoded classname of '$1' for matching"; fi
;;
*)
OPT=$(getopt --longoptions class: -n hdrop -- "$@")
Expand All @@ -131,6 +146,7 @@ if [[ -n $OPT ]]; then
case "$1" in
-a | --class)
CLASS="$2"
if $VERBOSE; then notify_low "hdrop: Extracted '$CLASS' from [COMMAND] for matching"; fi
;;
esac
fi
Expand All @@ -141,6 +157,11 @@ if $INSENSITIVE && [[ $(hyprctl clients -j | jq -r ".[] | select((.class |test(\
if $VERBOSE; then notify_low "hdrop: --insensitive -> Using class '$CLASS' after insensitive (partial) matching"; fi
fi

if [[ -n $CLASS_OVERRIDE ]]; then
if $VERBOSE; then notify_low "hdrop: --class -> Using given class '$CLASS_OVERRIDE' instead of '$CLASS' for matching"; fi
CLASS="$CLASS_OVERRIDE"
fi

if [[ $(hyprctl clients -j | jq -r ".[] | select(.class==\"$CLASS\" and .workspace.id!=$ACTIVE_WORKSPACE)") ]]; then
hyprctl dispatch -- movetoworkspacesilent "$ACTIVE_WORKSPACE","$CLASS" || notify "hdrop: Error moving '$COMMANDLINE' to current workspace"
hyprctl dispatch -- focuswindow "$CLASS" || notify "hdrop: Error focusing '$COMMANDLINE' on current workspace"
Expand Down
3 changes: 3 additions & 0 deletions hdrop.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ hdrop - run, show and hide programs on Hyprland
*-b, --background*
Changes the default behaviour: if the specified program is not running, launch it in the background instead of foreground. Thereafter 'hdrop -b' will work the same as without this flag.

*-c, --class*
Set classname of the program to be run. Use this if the classname is different from the name of the [COMMAND].

*-i, --insensitive*
Case insensitive partial matching of class names. Can work as a stopgap if a running program is not recognized and a new instance is launched instead. Note: incorrect matches may occur, adding a special handling of the program to `hdrop` is preferable.

Expand Down

0 comments on commit 97eb6e4

Please sign in to comment.