Réécriture de glurp
This commit is contained in:
parent
2f27db6afe
commit
aed4bb4807
1 changed files with 26 additions and 35 deletions
61
bin/glurp
61
bin/glurp
|
@ -1,61 +1,52 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
|
||||||
# Functions
|
error_usage() {
|
||||||
# Error
|
>&2 cat << EOF
|
||||||
function error {
|
Usage :
|
||||||
>&2 echo -e "\033[1;31mERROR:\033[0m $1"; shift
|
glurp full|area clip|file
|
||||||
exit "${1:-1}"
|
EOF
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Throw a value
|
screenshot_path() {
|
||||||
function throw-value {
|
printf %s "/tmp/screenshot-${USER}-$(date +%N).png"
|
||||||
error "Value \"${1}\" invalid for ${2}." 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function screenshot-path {
|
grim=grim
|
||||||
printf '%s%s-screenshot-%s.png' "${screenshot_d}/" "${LOGNAME}" "$(date +'%Y_%m_%d_%s')"
|
wl_copy_args="-t image/png"
|
||||||
}
|
|
||||||
|
|
||||||
# Variables
|
|
||||||
declare -a prepend _command append
|
|
||||||
screenshot_d=/tmp
|
|
||||||
|
|
||||||
# Arguments
|
# Arguments
|
||||||
selection_mode="$1"; shift
|
case "$1" in
|
||||||
saving_mode="$1" ; shift
|
|
||||||
|
|
||||||
# Command building
|
|
||||||
_command+=(grim)
|
|
||||||
case "$selection_mode" in
|
|
||||||
full)
|
full)
|
||||||
:
|
|
||||||
;;
|
;;
|
||||||
area)
|
area)
|
||||||
_command+=(-g -)
|
slurp=slurp
|
||||||
prepend+=(slurp)
|
pipe1='|'
|
||||||
|
grim_args="-g -"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
throw-value "$selection_mode" 'selection mode'
|
error_usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
case "$saving_mode" in
|
shift
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
clip)
|
clip)
|
||||||
_command+=(-)
|
pipe2='|'
|
||||||
append+=(wl-copy -t image/png)
|
wl_copy=wl-copy
|
||||||
;;
|
;;
|
||||||
file)
|
file)
|
||||||
_command+=("$(screenshot-path)")
|
grim_args="${grim_args} $(screenshot_path)"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
throw-value "$saving_mode" 'saving mode'
|
error_usage
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
shift
|
||||||
|
|
||||||
# Debug
|
[ -n "$wl_copy" ] && wl_copy="${wl_copy} ${wl_copy_args}"
|
||||||
#echo "${prepend[@]} | ${_command[@]} | ${append[@]}"
|
|
||||||
#exit 0
|
|
||||||
|
|
||||||
# Execution
|
# Execution
|
||||||
set -xe
|
set -xe
|
||||||
"${prepend[@]}" | "${_command[@]}" | "${append[@]}"
|
"$slurp" "$pipe1" "$grim" "$grim_args" "$pipe2" "$wl_copy"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue