Compare commits

...

3 commits

Author SHA1 Message Date
Hippolyte Chauvin
00df7a66c8 Merge branch 'devel' 2023-05-19 13:04:43 +02:00
Hippolyte Chauvin
b8c130e658 Merge branch 'test' into devel 2023-05-19 13:03:58 +02:00
Hippolyte Chauvin
aed4bb4807 Réécriture de glurp 2023-05-14 22:55:33 +02:00

View file

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