forked from ahurac/dotfiles
53 lines
903 B
Bash
Executable file
53 lines
903 B
Bash
Executable file
#!/bin/bash
|
|
|
|
# Functions
|
|
# Throw
|
|
function throw {
|
|
>&2 echo "$1"
|
|
exit "$2"
|
|
}
|
|
|
|
# Throw a value
|
|
function throw-value {
|
|
throw "Invalid value for \"$1\": \"$2\"" "$3"
|
|
}
|
|
|
|
# Variables
|
|
selection_mode="$1"
|
|
saving_mode="$2"
|
|
screenshot_d="/tmp"
|
|
_command=()
|
|
|
|
# Command building
|
|
_command+=("maim")
|
|
case "$selection_mode" in
|
|
"full")
|
|
:
|
|
;;
|
|
"area")
|
|
_command+=("-s")
|
|
;;
|
|
*)
|
|
throw-value "selection mode" "$selection_mode" 1
|
|
;;
|
|
esac
|
|
case "$saving_mode" in
|
|
"clip")
|
|
_command+=("|")
|
|
_command+=("xclip" "-selection" "clipboard" "-t" "image/png")
|
|
;;
|
|
"file")
|
|
_command+=(">" "${screenshot_d}/$(printf '%s-screenshot-%s.png' "$LOGNAME" "$(date +'%Y_%m_%d_%s')")")
|
|
;;
|
|
*)
|
|
throw-value "saving mode" "$saving_mode" 2
|
|
;;
|
|
esac
|
|
|
|
# Debug
|
|
#echo "${_command[@]}"
|
|
#exit 0
|
|
|
|
# Execution
|
|
"${_command[@]}"
|
|
|