1
0
Fork 0
forked from ahurac/dotfiles
ahuarc-dotfiles/bin/glurp
2023-04-13 00:25:00 +02:00

61 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
# Functions
# Error
function error {
>&2 echo -e "\033[1;31mERROR:\033[0m $1"; shift
exit "${1:-1}"
}
# Throw a value
function throw-value {
error "Value \"${1}\" invalid for ${2}." 1
}
function screenshot-path {
printf '%s%s-screenshot-%s.png' "${screenshot_d}/" "${LOGNAME}" "$(date +'%Y_%m_%d_%s')"
}
# Variables
declare -a prepend _command append
screenshot_d=/tmp
# Arguments
selection_mode="$1"; shift
saving_mode="$1" ; shift
# Command building
_command+=(grim)
case "$selection_mode" in
full)
:
;;
area)
_command+=(-g -)
prepend+=(slurp)
;;
*)
throw-value "$selection_mode" 'selection mode'
;;
esac
case "$saving_mode" in
clip)
_command+=(-)
append+=(wl-copy -t image/png)
;;
file)
_command+=("$(screenshot-path)")
;;
*)
throw-value "$saving_mode" 'saving mode'
;;
esac
# Debug
#echo "${prepend[@]} | ${_command[@]} | ${append[@]}"
#exit 0
# Execution
set -xe
"${prepend[@]}" | "${_command[@]}" | "${append[@]}"