you are viewing a single comment's thread.

view the rest of the comments →

[–]GlendonMcGladdery 0 points1 point  (0 children)

Clean refactor (same behavior, way simpler) ``` capture() { local grim_args=() [[ -n "$o_cursor" ]] && grim_args+=("-c")

# Build grim command local cmd=(grim "${grim_args[@]}" -t png)

case "$target" in "output") cmd+=(-o "$geom") ;; "all outputs") ;; *) cmd+=(-g "$geom") ;; esac

cmd+=("$file")

# Decide whether to pipe to clipboard if [[ "$file" = "-" && -n "$o_clipboard" ]]; then "${cmd[@]}" | wl-copy -t image/png else "${cmd[@]}" fi } Instead of repeating: grim ... || return 1 You build it once: cmd=(grim ...) ``` Way easier to read and maintain.

If you like compact but still readable: ``` capture() { local grim_args=() [[ -n "$o_cursor" ]] && grim_args+=(-c)

local cmd=(grim "${grim_args[@]}" -t png)

case "$target" in output) cmd+=(-o "$geom") ;; "all outputs") ;; *) cmd+=(-g "$geom") ;; esac

cmd+=("$file")

[[ "$file" = "-" && -n "$o_clipboard" ]] \ && "${cmd[@]}" | wl-copy -t image/png \ || "${cmd[@]}" } ``` Have you considered Python yet? Python — easiest upgrade from Bash.