all repos — dotfiles @ f425f13fc7a5ed852f6655e0ae85cd4cdfa51ae8

personal dotfiles

scrot_cmd: add usage info, silent mode and tweak notification
la-ninpre leobrekalini@gmail.com
Mon, 08 Nov 2021 23:33:57 +0300
commit

f425f13fc7a5ed852f6655e0ae85cd4cdfa51ae8

parent

1734342118584b19532843e2e9b7b81bb224d08a

1 files changed, 53 insertions(+), 18 deletions(-)

jump to
M bin/.local/bin/scrot_cmdbin/.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 @@

_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" - 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 + 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" + } main "$@"