aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorla-ninpre <leobrekalini@gmail.com>2021-11-08 23:33:57 +0300
committerla-ninpre <leobrekalini@gmail.com>2021-11-08 23:33:57 +0300
commitf425f13fc7a5ed852f6655e0ae85cd4cdfa51ae8 (patch)
tree38819c5331e587b85413fa1ec0f1716cf6dc2e75
parent1734342118584b19532843e2e9b7b81bb224d08a (diff)
downloaddotfiles-f425f13fc7a5ed852f6655e0ae85cd4cdfa51ae8.tar.gz
dotfiles-f425f13fc7a5ed852f6655e0ae85cd4cdfa51ae8.zip
scrot_cmd: add usage info, silent mode and tweak notification
-rwxr-xr-xbin/.local/bin/scrot_cmd71
1 files changed, 53 insertions, 18 deletions
diff --git a/bin/.local/bin/scrot_cmd b/bin/.local/bin/scrot_cmd
index 827ddf7..804d5fd 100755
--- a/bin/.local/bin/scrot_cmd
+++ b/bin/.local/bin/scrot_cmd
@@ -1,13 +1,31 @@
-#!/bin/sh
+#!/bin/sh -e
# a simple scrot wrapper to be used wm-agnostically
-scrot_cmd() {
- # shellcheck disable=SC2086
+usage() {
+ echo "usage: $0 [-n|--no-notify] [mode]"
+ echo
+ echo " -n, --no-notify do not show a notification on success"
+ echo
+ echo "modes:"
+ echo " -f, --full capture the whole screen"
+ echo " -a, --area select area and capture it"
+ echo " -c, --focused capture only focused window"
+ echo
+ echo "note: last specified mode will be chosen"
+}
+scrot_cmd() {
# scrot_cmd flags path
- scrot $1 "$2" -e "notify-send -t 3000 \"scrot\" \"screenshot \$f saved\""
+ _scrot_exec="echo \$f >/dev/null"
+ [ "$_scrot_notify" = "YES" ] && {
+ _scrot_exec="notify-send -t $_scrot_notify_duration \"scrot\" \
+ \"screenshot of $_scrot_human_readable_mode is saved to \$f\""
+ }
+
+ # shellcheck disable=SC2086
+ scrot $1 "$2" -e "$_scrot_exec"
}
main() {
@@ -15,21 +33,38 @@ main() {
_scrot_dir="$HOME/Pictures/Screenshots"
_scrot_name="%Y-%m-%d-%s_\$wx\$h_scrot.png"
_scrot_path="$_scrot_dir/$_scrot_name"
+ _scrot_notify="YES"
+ _scrot_notify_duration="3000"
+ _scrot_flags=""
+ _scrot_human_readable_mode="full screen"
+
+ for arg in "$@"
+ do
+ case $arg in
+ -n|--no-notify)
+ _scrot_notify="NO"
+ ;;
+ -f|--full)
+ _scrot_flags=""
+ _scrot_human_readable_mode="full screen"
+ ;;
+ -a|--area)
+ _scrot_flags="-sf"
+ _scrot_human_readable_mode="screen area"
+ ;;
+ -c|--focused)
+ _scrot_flags="-u"
+ _scrot_human_readable_mode="active window"
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+ done
+
+ scrot_cmd "$_scrot_flags" "$_scrot_path"
- case $1 in
- -f|--full)
- scrot_cmd "" "$_scrot_path"
- ;;
- -a|--area)
- scrot_cmd "-sf" "$_scrot_path"
- ;;
- -c|--focused)
- scrot_cmd "-u" "$_scrot_path"
- ;;
- *)
- exit 1
- ;;
- esac
}
main "$@"