From fd2c508cde1393cbaf4d25abdf9eaebbe5f73895 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 18 Nov 2023 20:21:50 +0100 Subject: bin/sbin: Use the new ‘notify’ API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .local/bin/chkb | 8 ++++++-- .local/bin/mc-pass | 8 +++++--- .local/bin/notify | 14 +++++++------- .local/bin/scst | 16 +++++++--------- .local/bin/send-package | 11 +++++++++++ .local/bin/uni | 7 +++++-- .local/bin/vlt | 36 +++++++++++++++++------------------- 7 files changed, 58 insertions(+), 42 deletions(-) create mode 100755 .local/bin/send-package (limited to '.local/bin') diff --git a/.local/bin/chkb b/.local/bin/chkb index b2f0d64..ac27e98 100755 --- a/.local/bin/chkb +++ b/.local/bin/chkb @@ -2,6 +2,9 @@ set -e +export NOTIFY_LONG=keyboard +export NOTIFY_SHORT=${0##*/} + readonly KEYBOARD=at-translated-set-2-keyboard s="$( @@ -19,8 +22,9 @@ s="$( if choice="$(echo "$s" | osel)" then - n="$(echo "$s" | sed -n "/$choice/=" | xargs expr -1 +)" + echo "$s" + n="$(echo "$s" | sed -n "/$choice/=" | { xargs expr -1 + || true; })" hyprctl switchxkblayout $KEYBOARD $n >/dev/null - notify "${0##*/}" keyboard 'Keyboard Layout Changed' \ + notify 'Keyboard Layout Changed' \ "The keyboard layout was changed to ‘$choice’" fi diff --git a/.local/bin/mc-pass b/.local/bin/mc-pass index 7dc868d..168e62e 100755 --- a/.local/bin/mc-pass +++ b/.local/bin/mc-pass @@ -1,12 +1,14 @@ #!/bin/sh +export NOTIFY_LONG='mc pass' +export NOTIFY_SHORT="${0##*/}" + trap ' wl-copy &2 + echo "Usage: ${0##*/} summary body [args ...]" >&2 exit 1 fi if [ -t 2 ] then - printf "%s: %s\n" "$1" "$4" >&2 + printf "%s: %s\n" "$NOTIFY_SHORT" "$2" >&2 else - t="$(echo "$2" | tr a-z A-Z)" - s="$3" - b="$4." - shift 4 + t="$(echo "$NOTIFY_LONG" | tr a-z A-Z)" + s="$1" + b="$2." + shift 2 notify-send "$@" -a "$t" "$s" "$b" fi diff --git a/.local/bin/scst b/.local/bin/scst index d1ad54a..51b00c1 100755 --- a/.local/bin/scst +++ b/.local/bin/scst @@ -2,9 +2,12 @@ set -e +export NOTIFY_LONG=screenshot +export NOTIFY_SHORT="${0##*/}" + xnotify() { - notify ${0##*/} screenshot 'Screenshot Copied' \ + notify 'Screenshot Copied' \ 'Screenshot successfully copied to the clipboard' \ -i "$filename" } @@ -35,10 +38,7 @@ fi [ -f "$filename" ] || exit 1 -opt="$( - printf 'Copy screenshot\nEdit- and copy screenshot\n' \ - | { osel || true; } -)" +opt="$(printf 'Copy screenshot\nEdit- and copy screenshot\n' | { osel || true; })" case "$opt" in 'Copy screenshot') @@ -46,13 +46,11 @@ case "$opt" in xnotify ;; 'Edit- and copy screenshot') - swappy -f "$filename" -o - \ - | pee wl-copy cat \ - | sponge "$filename" + swappy -f "$filename" -o - | pee wl-copy cat | sponge "$filename" xnotify ;; *) - notify ${0##*/} screenshot 'Screenshot Saved' \ + notify 'Screenshot Saved' \ "The screenshot ‘$filebase’ was successfully saved" \ -i "$filename" esac diff --git a/.local/bin/send-package b/.local/bin/send-package new file mode 100755 index 0000000..bcd7eb0 --- /dev/null +++ b/.local/bin/send-package @@ -0,0 +1,11 @@ +#!/bin/sh + +# Why not? + +readonly tmpl="${XDG_DATA_HOME:-$HOME/.local/share}/send-package/template" + +sed -En '/^Angel Cakes/,/^Doozies/s/(\t|\s{2,})/\n/gp' ~/doc/tit-names \ +| shuf -n1 \ +| tr A-Z a-z \ +| xargs -I{} -- sed 's/$REPLACEME/{}/' "$tmpl" \ +| smail diff --git a/.local/bin/uni b/.local/bin/uni index 4be2d86..3ed7ec4 100755 --- a/.local/bin/uni +++ b/.local/bin/uni @@ -2,6 +2,9 @@ set -e +export NOTIFY_LONG=unicode +export NOTIFY_SHORT="${0##*/}" + setup() { curl 'https://www.unicode.org/Public/UNIDATA/UnicodeData.txt' \ @@ -23,5 +26,5 @@ rune="$( | xargs printf )" -wl-copy -n "$rune" && notify uni unicode 'Rune Copied' \ - "The rune ‘$rune’ was copied to the clipboard" +wl-copy -n "$rune" \ +&& notify 'Rune Copied' "The rune ‘$rune’ was copied to the clipboard" diff --git a/.local/bin/vlt b/.local/bin/vlt index 72ec397..14c3c1f 100755 --- a/.local/bin/vlt +++ b/.local/bin/vlt @@ -2,13 +2,16 @@ set -e +export NOTIFY_LONG=vault +export NOTIFY_SHORT="${0##*/}" + sanitize() { s="${1#"${1%%[![:space:]]*}"}" s="${s%"${s##*[![:space:]]}"}" if [ "${#s}" -eq 0 ] then - xnotify 'Invalid Input' 'Empty strings do not constitute valid input' + notify 'Invalid Input' 'Empty strings do not constitute valid input' exit 1 fi } @@ -29,11 +32,6 @@ xecho() printf '%s' "$@" } -xnotify() -{ - notify "${0##*/}" vault "$1" "$2" -} - prompt() { if [ -t 2 ] @@ -89,7 +87,7 @@ add() xecho "$data" \ | jq -e --arg c "$c" --arg n "$n" '.[$c] | has($n) | not' >/dev/null || { - xnotify 'Failed To Add Password' "The password ‘$n’ already exists" + notify 'Failed To Add Password' "The password ‘$n’ already exists" exit 1 } @@ -111,7 +109,7 @@ add() "period": ($p | tonumber) }}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify '2FA Key Added' \ + [ ! -t 2 ] && notify '2FA Key Added' \ "The 2FA key ‘$n’ was added with the digit length ‘$d’ and period ‘$p’" else xprompt 'Password:' @@ -119,7 +117,7 @@ add() xecho "$data" \ | jq --arg c "$c" --arg n "$n" --arg s "$s" '.[$c] += {($n): $s}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify 'Password Added' \ + [ ! -t 2 ] && notify 'Password Added' \ "The password ‘$n’ was added to the category ‘$c’" fi } @@ -131,7 +129,7 @@ add_c() prompt 'Category to create:' xecho "$data" | jq -e --arg s "$s" 'has($s) | not' >/dev/null || { - xnotify 'Failed To Create Category' "The category ‘$s’ already exists" + notify 'Failed To Create Category' "The category ‘$s’ already exists" exit 1 } @@ -139,7 +137,7 @@ add_c() | jq --arg s "$s" '. + {($s): {}}' \ | enchive archive >"$VAULT" [ ! -t 2 ] && \ - xnotify 'Category Created' "The password category ‘$s’ was created" + notify 'Category Created' "The password category ‘$s’ was created" } get() @@ -163,13 +161,13 @@ get() ')" \ | wl-copy -no \ && [ ! -t 2 ] \ - && xnotify '2FA Code Copied To The Clipboard' \ + && notify '2FA Code Copied To The Clipboard' \ "The 2FA code for ‘$o’ was copied to the clipboard" else jq -r --arg c "$c" --arg o "$o" '.[$c] | .[$o]' \ | wl-copy -no \ && [ ! -t 2 ] \ - && xnotify 'Password Copied To The Clipboard' \ + && notify 'Password Copied To The Clipboard' \ "The password for ‘$o’ was copied to the clipboard" fi } @@ -199,7 +197,7 @@ rm_() xecho "$data" \ | jq --arg c "$c" --arg n "$n" 'del(.[$c] | .[$n])' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify 'Removed Password' \ + [ ! -t 2 ] && notify 'Removed Password' \ "The password ‘$n’ was removed from the category ‘$c’" } @@ -211,14 +209,14 @@ rm_c() xecho "$data" \ | jq -e --arg c "$c" '.[$c] | length == 0' >/dev/null || { - xnotify 'Failed To Remove Category' "The category ‘$c’ is not empty" + notify 'Failed To Remove Category' "The category ‘$c’ is not empty" exit 1 } xecho "$data" \ | jq --arg c "$c" 'del(.[$c])' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify 'Removed Category' "The category ‘$c’ was removed" + [ ! -t 2 ] && notify 'Removed Category' "The category ‘$c’ was removed" } edit() @@ -261,14 +259,14 @@ edit() "period": ($p | tonumber) }}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify '2FA Key Added' \ + [ ! -t 2 ] && notify '2FA Key Added' \ "The 2FA key ‘$n’ was added with the digit length ‘$d’ and period ‘$p’" else xprompt 'Password:' xecho "$data" \ | jq --arg c "$c" --arg n "$n" --arg s "$s" '.[$c] += {($n): $s}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify 'Password Edit' \ + [ ! -t 2 ] && notify 'Password Edit' \ "The password ‘$n’ in the category ‘$c’ was changed" fi } @@ -283,7 +281,7 @@ edit_c() | jq --arg o "$c" --arg n "$s" \ 'with_entries(if .key == $o then .key = $n else . end)' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && xnotify 'Category Edit' "The category ‘$c’ was renamed" + [ ! -t 2 ] && notify 'Category Edit' "The category ‘$c’ was renamed" } raw() -- cgit v1.2.3