Skip to content

Commit

Permalink
fix(grim): handle positional arguments and error message in notifyError
Browse files Browse the repository at this point in the history
- Introduced `POSITIONAL_ARGS` to collect and reassign positional
arguments using `set -- $POSITIONAL_ARGS` after flag parsing, ensuring
correct positional argument handling.
- Ensured flag parsing (`--notify`, `--cursor`, `--wait`) is processed
before positional arguments.
- Stored `$1` as `error_message` in `notifyError` to fix incorrect
reference during condition evaluation.
  • Loading branch information
Qubut committed Sep 12, 2024
1 parent 656aac0 commit 8a9d0e4
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions grimshot/grimshot
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ getTargetDirectory() {
}

parseArgs() {
while [ $# -gt 0 ]; do
key="$1"
POSITIONAL_ARGS=""

case $key in
while [ $# -gt 0 ]; do
case "$1" in
-n | --notify)
NOTIFY=yes
shift # past argument
shift
;;
-c | --cursor)
CURSOR=yes
shift # past argument
shift
;;
-w | --wait)
shift
Expand All @@ -46,12 +46,14 @@ parseArgs() {
fi
shift
;;
*) # unknown option
break # done with parsing --flags
*) # Treat anything else as a positional argument
POSITIONAL_ARGS="$POSITIONAL_ARGS $1" # Add positional argument to the string
shift
;;
esac
done

set -- $POSITIONAL_ARGS # Re-assign positional arguments
ACTION=${1:-usage}
SUBJECT=${2:-screen}
FILE=${3:-$(getTargetDirectory)/$(date -Ins).png}
Expand Down Expand Up @@ -102,11 +104,12 @@ notifyOk() {
notifyError() {
notify_enabled='[ "$NOTIFY" = "yes" ]'
TITLE=${2:-"Screenshot"}
MESSAGE=${1:-"Error taking screenshot with grim"}
errorMssg=$1
MESSAGE=${errorMssg:-"Error taking screenshot with grim"}

whenOtherwise "$notify_enabled" \
'notify -u critical "$TITLE" "$MESSAGE"' \
'echo "$1"'
'notify "$TITLE" "$MESSAGE" -u critical' \
'echo "$errorMssg"'
}

die() {
Expand Down

0 comments on commit 8a9d0e4

Please sign in to comment.