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