diff options
Diffstat (limited to '.local/bin/vlt')
-rwxr-xr-x | .local/bin/vlt | 37 |
1 files changed, 16 insertions, 21 deletions
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() |