Compare commits

..

No commits in common. "b8c130e658b1c0c9e48d6a89eca4fea6f70074b3" and "b2f69b3159f096b92d3cb54dae78b8125405fe36" 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[@]}"