diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-08-25 01:09:10 +0300 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-08-25 01:09:10 +0300 |
commit | 4817c1bc0222f7172d1acb9c18912a7e6f36a3c7 (patch) | |
tree | 866b26eb026059150f3cfbcbe3626b9cd09bdd36 /.local/bin | |
parent | a6afe32f76cfaaaf52befba24c5634e1f3ed1912 (diff) |
bin/sbin: Refactor shell scripts
Diffstat (limited to '.local/bin')
-rwxr-xr-x | .local/bin/chkb | 23 | ||||
-rwxr-xr-x | .local/bin/scst | 43 | ||||
-rwxr-xr-x | .local/bin/vlt | 10 |
3 files changed, 44 insertions, 32 deletions
diff --git a/.local/bin/chkb b/.local/bin/chkb index bc6da23..4f96877 100755 --- a/.local/bin/chkb +++ b/.local/bin/chkb @@ -2,18 +2,19 @@ set -e -export OSEL_GUI='wofi -d -r "echo \"%s\" | cut -f2 | xargs echo -n"' +export OSEL_GUI_FLAGS='-r "echo \"%s\" | cut -f2 | xargs echo -n"' -choice="`sed -En 's/\s*name\[Group1\]\s*=\s*"([^"]*)"\s*;\s*/\1/p' \ - ~/.xkb/symbols/mango \ - | sort \ - | nl -v0 -nln \ - | osel`" - -[ -n "$choice" ] && { +if choice="` + sed -En 's/\s*name\[Group1\]\s*=\s*"([^"]*)"\s*;\s*/\1/p' \ + ~/.xkb/symbols/mango \ + | sort \ + | nl -v0 -nln \ + | osel +`" +then hyprctl -j devices \ | jq -r '.keyboards[-1].name' \ - | xargs -I{} hyprctl switchxkblayout {} ${choice% *} + | xargs -I{} hyprctl switchxkblayout {} ${choice% *} >/dev/null notify-send -a "${0##*/}" -u normal 'Keyboard Layout Changed' \ - "The keyboard layout was changed to ‘${choice##* }’" -} + "The keyboard layout was changed to ‘${choice##* }’." +fi diff --git a/.local/bin/scst b/.local/bin/scst index 6b63009..5cce936 100755 --- a/.local/bin/scst +++ b/.local/bin/scst @@ -2,26 +2,30 @@ set -e -notify() { +notify() +{ notify-send -a ${0##*/} -i "$filename" 'Screenshot copied' \ - 'Screenshot successfully copied to the clipboard' + 'Screenshot successfully copied to the clipboard.' } -if [ $# -eq 1 -a "$1" = "-f" ]; then +if [ $# -eq 1 -a "$1" = "-f" ] +then fflag=true shift fi -[ $# -ge 1 ] && { +if [ $# -ge 1 ] +then echo "Usage: ${0##*/} [-f]" >&2 exit 1 -} +fi -outdir=${XDG_PICTURES_DIR:-$HOME/Pictures}/screen -filename="$outdir/`date +%F_%T.png`" +readonly outdir=${XDG_PICTURES_DIR:-$HOME/Pictures}/screen +readonly filename="$outdir/`date +%F_%T.png`" [ -d "$outdir" ] || mkdir -p "$outdir" -if ${fflag:-false}; then +if ${fflag:-false} +then grim "$filename" else slurp 2>/dev/null | ifne grim -g - "$filename" @@ -29,12 +33,17 @@ fi [ -f "$filename" ] || exit 1 -printf 'Copy screenshot\nEdit- and copy screenshot\n' \ - | osel \ - | if read res && [ "$res" = 'Copy screenshot' ]; then - wl-copy <"$filename" - notify - elif [ "$res" = 'Edit- and copy screenshot' ]; then - swappy -f "$filename" -o - | pee wl-copy cat | sponge "$filename" - notify - fi +opt="`printf 'Copy screenshot\nEdit- and copy screenshot\n' | osel`" + +case "$opt" in +'Copy screenshot') + wl-copy <"$filename" + notify + ;; +'Edit- and copy screenshot') + swappy -f "$filename" -o - \ + | pee wl-copy cat \ + | sponge "$filename" + notify + ;; +esac diff --git a/.local/bin/vlt b/.local/bin/vlt index 4121207..af68545 100755 --- a/.local/bin/vlt +++ b/.local/bin/vlt @@ -15,10 +15,12 @@ sanitize() usage() { - echo "Usage: ${0##*/} add [-c]" >&2 - echo " ${0##*/} edit [-c]" >&2 - echo " ${0##*/} get" >&2 - echo " ${0##*/} rm [-c]" >&2 + cat <<-EOF >&2 + Usage: ${0##*/} add [-c] + ${0##*/} edit [-c] + ${0##*/} get + ${0##*/} rm [-c] + EOF exit 1 } |