dotfiles/bin/glurp
2023-05-14 22:55:33 +02:00

52 lines
738 B
Bash
Executable file

#!/bin/sh
error_usage() {
>&2 cat << EOF
Usage :
glurp full|area clip|file
EOF
exit 1
}
screenshot_path() {
printf %s "/tmp/screenshot-${USER}-$(date +%N).png"
}
grim=grim
wl_copy_args="-t image/png"
# Arguments
case "$1" in
full)
;;
area)
slurp=slurp
pipe1='|'
grim_args="-g -"
;;
*)
error_usage
;;
esac
shift
case "$1" in
clip)
pipe2='|'
wl_copy=wl-copy
;;
file)
grim_args="${grim_args} $(screenshot_path)"
;;
*)
error_usage
;;
esac
shift
[ -n "$wl_copy" ] && wl_copy="${wl_copy} ${wl_copy_args}"
# Execution
set -xe
"$slurp" "$pipe1" "$grim" "$grim_args" "$pipe2" "$wl_copy"