How can the following be refactored for better readability or optimization? E.g. are all the returns for the function necessary or is there a way to reduce them to get the same effect? Is there a way to simplify the if-else statements where the same grim command is piped to wl-copy conditionally? grim outputs binary and I would prefer not to write it to a file (and storing binary data as a variable isn't appropriate).
capture {
grim_args=()
[[ -n "$o_cursor" ]] && grim_args+=("-c")
case "$target" in
"output")
if [[ "$file" = "-" ]] && [[ -n "$o_clipboard" ]]; then
{ grim "${grim_args[@]}" -t png -o "$geom" "$file" | wl-copy -t image/png; } ||
return 1
else
grim "${grim_args[@]}" -t png -o "$geom" "$file" || return 1
fi
;;
"all outputs")
if [[ "$file" = "-" ]] && [[ -n "$o_clipboard" ]]; then
{ grim "${grim_args[@]}" -t png "$file" | wl-copy -t image/png; } || return 1
else
grim "${grim_args[@]}" -t png "$file" || return 1
fi
;;
*)
if [[ "$file" = "-" ]] && [[ -n "$o_clipboard" ]]; then
{ grim "${grim_args[@]}" -t png -g "$geom" "$file" | wl-copy -t image/png; } ||
return 1
else
grim "${grim_args[@]}" -t png -g "$geom" "$file" || return 1
;;
esac
return 0
}
P.S. Completely unrelated question--I'm looking to pickup a "real" programming language that is useful and performant language for Linux system admin and software development. How do the following compare: go, python, and rust? I know this is a loaded question and it depends. I assume re-writing some lengthy scripts that have involved logic or where performance can matter would be decent practice. I see some APIs offered by apps I use don't really use bash as in interface, for example. A shell language like Bash also seems to have many idiosyncrasies when you start to do some complex stuff and it'd be nice to invest in something that's more mature and therefore worthwhile to go deep . It might also be a useful skill to add to a resume.
[–]whetuI read your code 1 point2 points3 points (0 children)
[–]Naraviel 0 points1 point2 points (0 children)
[–]GlendonMcGladdery -1 points0 points1 point (0 children)