Skip to content

Commit

Permalink
hdrop: fix flag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweber committed Dec 28, 2023
1 parent 92f1dac commit cb933ab
Showing 1 changed file with 40 additions and 37 deletions.
77 changes: 40 additions & 37 deletions hdrop
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,35 @@ notify_low() {
echo "$@"
}

BACKGROUND=""
INSENSITIVE=false
VERBOSE=false
hdrop_flags() {
while true; do
case "$1" in
-h | --help)
print_help
exit
;;
-V | --version)
print_version
exit
;;
-b | --background)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
shift
;;
-i | --insensitive)
INSENSITIVE=true
shift
;;
-v | --verbose)
VERBOSE=true
shift
;;
*) break ;;
esac
done
}

# shopt -s extglob
HDROP_FLAGS=()

while true; do
case "$1" in
Expand All @@ -67,45 +91,24 @@ while true; do
print_help
exit 1
;;
-h | --help)
print_help
exit
;;
-V | --version)
print_version
exit
;;
-b | --background)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
shift
;;
-i | --insensitive)
INSENSITIVE=true
shift
;;
-v | --verbose)
VERBOSE=true
shift
;;
-bi | -ib)
BACKGROUND="hyprctl dispatch -- exec [workspace special:hdrop silent] "
INSENSITIVE=true
shift
;;
-vi | -iv)
INSENSITIVE=true
VERBOSE=true
-*)
HDROP_FLAGS+=("$1")
shift
;;
-*)
notify "hdrop: Unrecognized flag '$1'" "Run 'hdrop -h' for more information"
print_help
exit 1
*)
break
;;
*) break ;;
esac
done

BACKGROUND=""
INSENSITIVE=false
VERBOSE=false

if [[ -n $HDROP_FLAGS ]]; then
hdrop_flags $(getopt --options bivVh --longoptions background,insensitive,verbose,version,help -n hdrop -- "${HDROP_FLAGS[@]}")
fi

CLASS="$1"
COMMANDLINE="${*:1}"
ACTIVE_WORKSPACE="$(hyprctl activeworkspace -j | jq -r .id)" || notify "hdrop: Error executing dependencies 'hyprctl' or 'jq'" "Check terminal output of 'hdrop $COMMANDLINE'"
Expand Down

0 comments on commit cb933ab

Please sign in to comment.