···3939 " -a - record desktop audio" \
4040 " -c - copy image to clipboard" \
4141 " -h - display this message" \
4242- " -m - record microphone audio"
4242+ " -m - record microphone audio" \
4343+ " -o - output to use"
4344}
44454546# Determine the action to run
···5354shift
54555556# Determine options to run with based on arguments
5757+# (I need to stop)
5658for flag in "$@"
5759do
5860 # Make sure arguments start with '-' and are atleast 2 characters long
···6466 esac
65676668 # Split arguments to be 1 character long and determine options to use
6767- flag=${flag#-}
6868- while [ "$flag" ]
6969+ args=${flag#-}
7070+ while [ "$args" ]
6971 do
7070- a=${flag%${flag#?}}
7272+ a=${args%${args#?}}
7173 case $a in
7274 a ) desktop_audio=true ;;
7375 c ) copy_clipboard=true ;;
7476 h ) usage; exit 0 ;;
7577 m ) microphone=true ;;
7878+ o ) aargs=$*
7979+ output=${aargs##*${flag}}; output=${output#\ }; output=${output%%\ *}
8080+ [ "${output}" ] || printf '%s\n' "${0##*/}: -o: missing output" 1>&2 ;;
7681 * ) printf '%s\n' "${0##*/}: -$a: invalid argument" 1>&2
7782 usage 1>&2; exit 1 ;;
7883 esac
7979- flag=${flag#?}
8484+ args=${args#?}
8085 done
8186done
8287unset args arg
···140145 filename="$scr_pic_dir/$pic_filename"
141146142147 # Get the geometry of the screenshot from the user and take the screenshot
143143- grim -g "$(slurp)" "$filename" > "$SCR_CACHE_DIR/pic.log" 2>&1
148148+ if [ "$output" ]; then set -- -o "$output"; else set -- -g "$(slurp)"; fi
149149+ grim "$@" "$filename" > "$SCR_CACHE_DIR/pic.log" 2>&1
144150145151 # Copy the image to the system clipboard
146152 $copy_clipboard && { wl-copy <"$filename" > "$SCR_CACHE_DIR/copy.log" 2>&1; }
···178184 # Intercept Ctrl+C and exit wf-recorder instead of the script
179185 trap 'kill -2 $rec_pid' INT
180186187187+ if [ "$output" ]; then set -- -o "$output"; else set -- -g "$(slurp)"; fi
181188 # Word splitting is favorable here
182189 # shellcheck disable=SC2086
183183- wf-recorder $args -g "$(slurp)" -f "$filename" > "$SCR_CACHE_DIR/rec.log" 2>&1 &
190190+ wf-recorder $args "$@" -f "$filename" > "$SCR_CACHE_DIR/rec.log" 2>&1 &
184191 rec_pid=$!
185192 printf '%s' "Press Ctrl+C to stop recording. " 1>&2
186193 wait $rec_pid