2015-05-11 23:41:56 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2020-12-01 16:27:21 +01:00
|
|
|
|
## Try to use flameshot to get a screenshot
|
|
|
|
|
### See https://github.com/flameshot-org/flameshot
|
|
|
|
|
## Or try to use scrot
|
2017-04-12 14:58:53 +02:00
|
|
|
|
|
2020-12-01 16:52:17 +01:00
|
|
|
|
# Vars {{{
|
|
|
|
|
readonly PROGNAME=$(basename "${0}")
|
|
|
|
|
readonly NBARGS="${#}"
|
|
|
|
|
## Test if DEBUG is already defined (by parent script,…)
|
|
|
|
|
[ -z "${DEBUG}" ] && DEBUG=1
|
|
|
|
|
|
|
|
|
|
## Colors
|
|
|
|
|
readonly RED='\033[0;31m'
|
|
|
|
|
readonly RESET='\033[0m'
|
|
|
|
|
readonly COLOR_DEBUG="${PURPLE}"
|
|
|
|
|
# }}}
|
|
|
|
|
debug_message() { # {{{
|
|
|
|
|
|
|
|
|
|
local_debug_message="${1}"
|
|
|
|
|
|
|
|
|
|
## Print message if DEBUG is enable (=0)
|
|
|
|
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6b\e[m\n' "DEBUG − ${PROGNAME} : ${local_debug_message}"
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
# Manage arguments # {{{
|
|
|
|
|
|
|
|
|
|
## If there is argument(s)
|
|
|
|
|
if [ ! "${NBARGS}" -eq "0" ]; then
|
|
|
|
|
|
|
|
|
|
manage_arg="0"
|
|
|
|
|
|
|
|
|
|
## If the first argument is not an option {{{
|
|
|
|
|
## Use it to delay screenshot
|
|
|
|
|
if ! printf -- '%s' "${1}" | grep -q -E -- "^-+";
|
|
|
|
|
then
|
2020-12-01 17:14:04 +01:00
|
|
|
|
## Use this argument for delay_screenshot (in seconds)
|
2020-12-01 16:52:17 +01:00
|
|
|
|
delay_screenshot="${1}"
|
2020-12-01 17:14:04 +01:00
|
|
|
|
## Enable DELAYED screenshot mode
|
|
|
|
|
DELAYED_MODE="0"
|
2020-12-01 16:52:17 +01:00
|
|
|
|
|
|
|
|
|
## Switch to the next argument
|
|
|
|
|
shift
|
|
|
|
|
manage_arg=$((manage_arg+1))
|
|
|
|
|
fi
|
|
|
|
|
## }}}
|
|
|
|
|
# Parse all options (start with a "-") one by one
|
|
|
|
|
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
|
|
|
|
|
|
|
|
|
|
case "${1}" in
|
|
|
|
|
-d|--delay ) ## Add a delay
|
2020-12-01 17:14:04 +01:00
|
|
|
|
## Enable DELAYED screenshot mode
|
|
|
|
|
DELAYED_MODE="0"
|
2020-12-01 16:52:17 +01:00
|
|
|
|
## Move to the next argument
|
|
|
|
|
shift
|
2020-12-01 17:14:04 +01:00
|
|
|
|
## Define the delay with this argument (in seconds)
|
2020-12-01 16:52:17 +01:00
|
|
|
|
delay_screenshot="${1}"
|
|
|
|
|
;;
|
|
|
|
|
* ) ## unknow option
|
|
|
|
|
printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
|
|
|
|
|
printf '%b\n' "---"
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
debug_message "Arguments management − \
|
|
|
|
|
${RED}${1}${COLOR_DEBUG} option managed."
|
|
|
|
|
|
|
|
|
|
## Move to the next argument
|
|
|
|
|
shift
|
|
|
|
|
manage_arg=$((manage_arg+1))
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
debug_message "Arguments management − \
|
|
|
|
|
${RED}${manage_arg}${COLOR_DEBUG} argument(s) successfully managed."
|
|
|
|
|
else
|
|
|
|
|
debug_message "Arguments management − \
|
|
|
|
|
No arguments/options to manage."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# }}}
|
|
|
|
|
|
|
|
|
|
## Use Flameshot if available {{{
|
2020-12-01 16:27:21 +01:00
|
|
|
|
if [ "$(command -v flameshot)" ]; then
|
2020-12-01 17:14:04 +01:00
|
|
|
|
if [ "${DELAYED_MODE}" -eq "0" ]; then
|
|
|
|
|
## Convert delay screenshot to milliseconds
|
|
|
|
|
delay_screenshot="$(( ${delay_screenshot} * 1000 ))"
|
|
|
|
|
## Open flameshot after "${delay_screenshot}" seconds
|
|
|
|
|
flameshot gui --path /tmp --delay "${delay_screenshot}"
|
|
|
|
|
else
|
|
|
|
|
## Open flameshot
|
|
|
|
|
flameshot gui --path /tmp --delay 50
|
|
|
|
|
fi
|
2020-12-01 16:52:17 +01:00
|
|
|
|
## }}}
|
|
|
|
|
else ## Use Scrot {{{
|
2020-12-01 16:27:21 +01:00
|
|
|
|
# -s : Interactively select a window or rectangle with the mouse.
|
|
|
|
|
# -e : Directly open the screenshot with Gimp then delete it
|
|
|
|
|
|
|
|
|
|
scrot -s -m -e 'gimp $f ; mv $f /tmp/'
|
|
|
|
|
|
|
|
|
|
fi
|
2020-12-01 16:52:17 +01:00
|
|
|
|
## }}}
|