diff options
author | Timo Wilken | 2022-11-25 00:33:03 +0100 |
---|---|---|
committer | Timo Wilken | 2022-11-25 00:33:03 +0100 |
commit | 1a48d38590731550d37ffa522d32d14c7208cd3f (patch) | |
tree | 6837afe99c7359eea381deedc928595ff83a1cce | |
parent | 37f71219784bed16bdd5b950c38bd0565dd02884 (diff) |
Manage rofi menu scripts through Guix home
-rw-r--r-- | home-configuration.scm | 3 | ||||
-rwxr-xr-x | passmenu | 91 | ||||
-rwxr-xr-x | sessionmenu | 15 |
3 files changed, 109 insertions, 0 deletions
diff --git a/home-configuration.scm b/home-configuration.scm index f65e7bfa..50510e3a 100644 --- a/home-configuration.scm +++ b/home-configuration.scm @@ -328,6 +328,9 @@ replacement spec (to which `regexp-substitute/global' is applied)." (".local/bin/kdiff" ,(program-file "kdiff" #~(apply execl #$(package-binary "kitty") "kitty" "+kitten" "diff" (cdr (command-line))))) + ;; With #:recursive? #t, Guix keeps the files' permission bits, i.e. makes them executable. + (".local/bin/sessionmenu" ,(local-file "sessionmenu" #:recursive? #t)) ; rofi logout/reboot menu + (".local/bin/passmenu" ,(local-file "passmenu" #:recursive? #t)) ; rofi passwords menu (".local/bin/volume" ,(program-file "volume" diff --git a/passmenu b/passmenu new file mode 100755 index 00000000..abeb98fb --- /dev/null +++ b/passmenu @@ -0,0 +1,91 @@ +#!/bin/sh -e + +usage() { + cat << EOF +$(basename "$0") [-c | -p | -a] + + -c, --clip copy the user-selected password to the clipboard + -p, --type-pass auto-type the user-selected password only + -a, --type-all auto-type the user-selected username <tab> password + -h, --help show this help message and exit + -v, --version show the program version number and exit + +Later options override conflicting earlier ones. +If no option is given, -c/--clip is the default. +GNU-style combination of short options (e.g. -pa) is not supported. + +Abnormal exit codes: + 1 no password selected by user + 2 invalid command-line argument + 3 internal error + +(C) 2019-2022 Timo Wilken; MIT Licence. +Adapted from https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu. +EOF +} + +version() { + # Changelog: + # 1.0.0 (2019-??-??) initial version + # 1.0.1 (2022-07-17) script formatting; throw away passwords asap + # 1.0.2 (2022-10-??) remove fix_xdotool; this should be done on login + echo "$(basename "$0") 1.0.2" +} + +password_names() { + find "${PASSWORD_STORE_DIR-$HOME/.password-store}" -name '*.gpg' -type f \ + -printf '%P\n' | sed 's/\.gpg$//' +} + +extract_key() { + sed -rn "s/^$1:\\s+(.+)\$/\\1/p" +} + +type_stdin() { + tr -d '\n' | xdotool getactivewindow type --clearmodifiers --file - +} + +## Command-line arguments +mode=clip +while [ $# -gt 0 ]; do + case "$1" in + -o|--type-otp) mode=type-otp; shift;; + -p|--type-pass) mode=type-pass; shift;; + -a|--type-all) mode=type-all; shift;; + -c|--clip) mode=clip; shift;; + -h|--help) usage; exit;; + -v|--version) version; exit;; + + *) + echo "$(basename "$0"): unknown option: $1" >&2 + usage >&2 + exit 2;; + esac +done + +## Password selection menu +password_name=$(password_names | rofi -dmenu -i -p Password -no-custom) +[ -n "$password_name" ] || exit 1 + +## Password typing +case "$mode" in + clip) + # Suppress "copied ... to clipboard" notice on stdout. + pass show --clip "$password_name" > /dev/null;; + + type-otp) + pass otp "$password_name" | type_stdin;; + + type-*) + entry=$(pass show "$password_name") + if [ "$mode" = type-all ]; then + echo "$entry" | extract_key username | type_stdin + xdotool getactivewindow key Tab + fi + echo "$entry" | head -1 | type_stdin + unset entry;; + + *) + echo "$(basename "$0"): internal error: unknown mode: $mode" >&2 + exit 3;; +esac diff --git a/sessionmenu b/sessionmenu new file mode 100755 index 00000000..01f961e2 --- /dev/null +++ b/sessionmenu @@ -0,0 +1,15 @@ +#!/bin/sh -e +case $1 in + quit) exit 0 ;; + 'Reload i3 configuration') i3-msg reload >&2 ;; + 'Log out') i3-msg exit >&2 ;; + 'Shutdown') sudo -n /run/current-system/profile/sbin/shutdown >&2 ;; + 'Reboot') sudo -n /run/current-system/profile/sbin/reboot >&2 ;; + *) + printf '\0%s\x1f%s\n' prompt 'Session' + printf '%s\0icon\x1f%s\n' \ + 'Reload i3 configuration' reload \ + 'Log out' system-log-out \ + 'Shutdown' system-shutdown \ + 'Reboot' system-reboot ;; +esac |