dotfiles/bin/glurp

53 lines
738 B
Text
Raw Normal View History

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