diff options
author | Thomas Voss <mail@thomasvoss.com> | 2023-11-04 23:01:55 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2023-11-04 23:01:55 +0100 |
commit | 7b68345ead9a3f5030a5aeb7eeb2d54b9a367191 (patch) | |
tree | 4baa41612157e017ba49c1314100e1bf04d57d6c | |
parent | 54a957bf5b27d0d8bc73365b5f3509bff9963bda (diff) |
notify: Add the notify script
-rwxr-xr-x | .config/eww/scripts/battery | 5 | ||||
-rwxr-xr-x | .config/eww/scripts/email-listener | 23 | ||||
-rwxr-xr-x | .local/bin/chkb | 4 | ||||
-rwxr-xr-x | .local/bin/mc-pass | 4 | ||||
-rwxr-xr-x | .local/bin/notify | 18 | ||||
-rwxr-xr-x | .local/bin/scst | 11 | ||||
-rwxr-xr-x | .local/bin/vlt | 37 |
7 files changed, 62 insertions, 40 deletions
diff --git a/.config/eww/scripts/battery b/.config/eww/scripts/battery index 600dfb3..69019a6 100755 --- a/.config/eww/scripts/battery +++ b/.config/eww/scripts/battery @@ -17,8 +17,9 @@ then if (set +e; [ $(($now - ${was:-0} > 60)) -eq 1 ]) then - notify-send -a 'battery' -u critical 'Battery Low' \ - 'The current battery level is below 20%. Plug the device into a charger ASAP.' + notify battery battery 'Battery Low' \ + 'The current battery level is below 20%. Plug the device into a charger ASAP' \ + -u critical echo $now >"$TS_FILE" fi fi diff --git a/.config/eww/scripts/email-listener b/.config/eww/scripts/email-listener index c676676..861bf28 100755 --- a/.config/eww/scripts/email-listener +++ b/.config/eww/scripts/email-listener @@ -1,5 +1,8 @@ #!/bin/sh +readonly CACHE="${XDG_CACHE_HOME:=$HOME/.cache}/email-listener" +touch "$CACHE" + count() { local cur=`find "$MAILDIR"/*/Inbox/cur -type f | wc -l` @@ -20,26 +23,30 @@ count() [ $new -gt 0 ] && printf ' (%d Unread)' $new echo - new_mails=$new + echo $new >"$CACHE" } { while sleep 1 do - if [ ${new_mails:=0} -gt ${prev:=0} ] + read new_mails <"$CACHE" + if [ $new_mails -gt ${prev:=0} ] then - case $new_mails in + local title + local desc + + case $((new_mails - prev)) in 1) - local title='New Email' - local desc='1 new email has been received.' + title='New Email' + desc='1 new email has been received' ;; *) - local title='New Emails' - local desc="$new_mails new emails have been received." + title='New Emails' + desc="$new_mails new emails have been received" ;; esac - notify-send -a email "$title" "$desc" + notify email email "$title" "$desc" prev=$new_mails fi done diff --git a/.local/bin/chkb b/.local/bin/chkb index 2edc0d6..1dcf729 100755 --- a/.local/bin/chkb +++ b/.local/bin/chkb @@ -16,6 +16,6 @@ if choice="` `" then hyprctl switchxkblayout $KEYBOARD ${choice% *} >/dev/null - notify-send -a "${0##*/}" 'Keyboard Layout Changed' \ - "The keyboard layout was changed to ‘${choice##* }’." + notify "${0##*/}" keyboard 'Keyboard Layout Changed' \ + "The keyboard layout was changed to ‘${choice##* }’" fi diff --git a/.local/bin/mc-pass b/.local/bin/mc-pass index 046a565..7dc868d 100755 --- a/.local/bin/mc-pass +++ b/.local/bin/mc-pass @@ -2,11 +2,11 @@ trap ' wl-copy </dev/null - notify-send -a "${0##*/}" "Password Cleared" \ + notify "${0##*/}" "mc pass" "Password Cleared" \ "The password was cleared from the clipboard." ' INT EXIT TERM vlt raw Email thomasvoss@live.com | wl-copy -notify-send -a "${0##*/}" 'Password Copied' \ +notify "${0##*/}" 'mc pass' 'Password Copied' \ 'The password will be cleared from the clipboard in 10 seconds.' sleep 10 diff --git a/.local/bin/notify b/.local/bin/notify new file mode 100755 index 0000000..39669fe --- /dev/null +++ b/.local/bin/notify @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ $# -lt 4 ] +then + echo "Usage: ${0##*/} short long summary body [args ...]" >&2 + exit 1 +fi + +if [ -t 2 ] +then + printf "%s: %s\n" "$1" "$4" >&2 +else + t="$(echo "$2" | tr a-z A-Z)" + s="$3" + b="$4." + shift 4 + notify-send "$@" -a "$t" "$s" "$b" +fi diff --git a/.local/bin/scst b/.local/bin/scst index f24fdb4..43ba261 100755 --- a/.local/bin/scst +++ b/.local/bin/scst @@ -2,10 +2,11 @@ set -e -notify() +xnotify() { - notify-send -a ${0##*/} -i "$filename" 'Screenshot Copied' \ - 'Screenshot successfully copied to the clipboard.' + notify ${0##*/} screenshot 'Screenshot Copied' \ + 'Screenshot successfully copied to the clipboard' \ + -i "$filename" } if [ $# -eq 1 -a "$1" = "-f" ] @@ -38,12 +39,12 @@ opt="`printf 'Copy screenshot\nEdit- and copy screenshot\n' | osel`" case "$opt" in 'Copy screenshot') wl-copy <"$filename" - notify + xnotify ;; 'Edit- and copy screenshot') swappy -f "$filename" -o - \ | pee wl-copy cat \ | sponge "$filename" - notify + xnotify ;; esac diff --git a/.local/bin/vlt b/.local/bin/vlt index 397f191..0f253b3 100755 --- a/.local/bin/vlt +++ b/.local/bin/vlt @@ -8,7 +8,7 @@ sanitize() s="${s%"${s##*[![:space:]]}"}" if [ "${#s}" -eq 0 ] then - notify 'Invalid Input' 'Empty strings do not constitute valid input' + xnotify 'Invalid Input' 'Empty strings do not constitute valid input' exit 1 fi } @@ -29,14 +29,9 @@ xecho() printf '%s' "$@" } -notify() +xnotify() { - if [ -t 2 ] - then - printf "%s: %s\n" "${0##*/}" "$2" >&2 - else - notify-send -a "${0##*/}" "$1" "$2." - fi + notify "${0##*/}" vault "$1" "$2" } prompt() @@ -94,7 +89,7 @@ add() xecho "$data" \ | jq -e --arg c "$c" --arg n "$n" '.[$c] | has($n) | not' >/dev/null || { - notify 'Failed To Add Password' "The password ‘$n’ already exists" + xnotify 'Failed To Add Password' "The password ‘$n’ already exists" exit 1 } @@ -116,7 +111,7 @@ add() "period": ($p | tonumber) }}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && notify '2FA Key Added' \ + [ ! -t 2 ] && xnotify '2FA Key Added' \ "The 2FA key ‘$n’ was added with the digit length ‘$d’ and period ‘$p’" else xprompt 'Password:' @@ -124,7 +119,7 @@ add() xecho "$data" \ | jq --arg c "$c" --arg n "$n" --arg s "$s" '.[$c] += {($n): $s}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && notify 'Password Added' \ + [ ! -t 2 ] && xnotify 'Password Added' \ "The password ‘$n’ was added to the category ‘$c’" fi } @@ -136,7 +131,7 @@ add_c() prompt 'Category to create:' xecho "$data" | jq -e --arg s "$s" 'has($s) | not' >/dev/null || { - notify 'Failed To Create Category' "The category ‘$s’ already exists" + xnotify 'Failed To Create Category' "The category ‘$s’ already exists" exit 1 } @@ -144,7 +139,7 @@ add_c() | jq --arg s "$s" '. + {($s): {}}' \ | enchive archive >"$VAULT" [ ! -t 2 ] && \ - notify 'Category Created' "The password category ‘$s’ was created" + xnotify 'Category Created' "The password category ‘$s’ was created" } get() @@ -168,13 +163,13 @@ get() '`" \ | wl-copy -no \ && [ ! -t 2 ] \ - && notify '2FA Code Copied To The Clipboard' \ + && xnotify '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 ] \ - && notify 'Password Copied To The Clipboard' \ + && xnotify 'Password Copied To The Clipboard' \ "The password for ‘$o’ was copied to the clipboard" fi } @@ -204,7 +199,7 @@ rm_() xecho "$data" \ | jq --arg c "$c" --arg n "$n" 'del(.[$c] | .[$n])' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && notify 'Removed Password' \ + [ ! -t 2 ] && xnotify 'Removed Password' \ "The password ‘$n’ was removed from the category ‘$c’" } @@ -216,14 +211,14 @@ rm_c() xecho "$data" \ | jq -e --arg c "$c" '.[$c] | length == 0' >/dev/null || { - notify 'Failed To Remove Category' "The category ‘$c’ is not empty" + xnotify '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 ] && notify 'Removed Category' "The category ‘$c’ was removed" + [ ! -t 2 ] && xnotify 'Removed Category' "The category ‘$c’ was removed" } edit() @@ -266,14 +261,14 @@ edit() "period": ($p | tonumber) }}' \ | enchive archive >"$VAULT" - [ ! -t 2 ] && notify '2FA Key Added' \ + [ ! -t 2 ] && xnotify '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 ] && notify 'Password Edit' \ + [ ! -t 2 ] && xnotify 'Password Edit' \ "The password ‘$n’ in the category ‘$c’ was changed" fi } @@ -288,7 +283,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 ] && notify 'Category Edit' "The category ‘$c’ was renamed" + [ ! -t 2 ] && xnotify 'Category Edit' "The category ‘$c’ was renamed" } raw() |