Compare commits

..

No commits in common. "00df7a66c81f92211f16c1ec4a413ce0e1b062fa" and "9518f7e069f90eb575423837982093a62abd62a3" have entirely different histories.

View file

@ -1,52 +1,61 @@
#!/bin/sh
#!/bin/bash
error_usage() {
>&2 cat << EOF
Usage :
glurp full|area clip|file
EOF
exit 1
# Functions
# Error
function error {
>&2 echo -e "\033[1;31mERROR:\033[0m $1"; shift
exit "${1:-1}"
}
screenshot_path() {
printf %s "/tmp/screenshot-${USER}-$(date +%N).png"
# Throw a value
function throw-value {
error "Value \"${1}\" invalid for ${2}." 1
}
grim=grim
wl_copy_args="-t image/png"
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
case "$1" in
selection_mode="$1"; shift
saving_mode="$1" ; shift
# Command building
_command+=(grim)
case "$selection_mode" in
full)
:
;;
area)
slurp=slurp
pipe1='|'
grim_args="-g -"
_command+=(-g -)
prepend+=(slurp)
;;
*)
error_usage
throw-value "$selection_mode" 'selection mode'
;;
esac
shift
case "$1" in
case "$saving_mode" in
clip)
pipe2='|'
wl_copy=wl-copy
_command+=(-)
append+=(wl-copy -t image/png)
;;
file)
grim_args="${grim_args} $(screenshot_path)"
_command+=("$(screenshot-path)")
;;
*)
error_usage
throw-value "$saving_mode" 'saving mode'
;;
esac
shift
[ -n "$wl_copy" ] && wl_copy="${wl_copy} ${wl_copy_args}"
# Debug
#echo "${prepend[@]} | ${_command[@]} | ${append[@]}"
#exit 0
# Execution
set -xe
"$slurp" "$pipe1" "$grim" "$grim_args" "$pipe2" "$wl_copy"
"${prepend[@]}" | "${_command[@]}" | "${append[@]}"