summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyush Agarwal <ayushnix@fastmail.com>2023-03-01 22:50:24 +0530
committerAyush Agarwal <ayushnix@fastmail.com>2023-03-18 01:23:57 +0530
commit5accf42f6c34f1159947b3e3f5bc1a1a3c346145 (patch)
treed841c925b9be2b1824b99887fb61ebec48551cce
parent42f0ca01beac60dd771f9d99fff00fccdc529f20 (diff)
feat: implement custom keyboard shortcuts
This feature was requested in https://github.com/ayushnix/tessen/issues/30 and https://github.com/ayushnix/tessen/issues/32 This feature is inspired from rofi-pass. However, rofi-pass implemented this feature only for rofi by using its command line flags. Since tessen intends to work with multiple dmenu scripts, I've mapped the actions to exit codes instead. This would allow users to map exit codes greater than 10 to whatever keybindings they prefer.
-rwxr-xr-xtessen21
1 files changed, 21 insertions, 0 deletions
diff --git a/tessen b/tessen
index 3a07aa6..b3183cd 100755
--- a/tessen
+++ b/tessen
@@ -26,6 +26,7 @@ tsn_delay=100
tsn_config="${XDG_CONFIG_HOME:-$HOME/.config}"/tessen/config
# variables with sensitive data which will be manually unset using _clear
declare tsn_passfile tsn_username tsn_password tsn_url tsn_autotype chosen_key
+declare -i _EXIT_STATUS
declare -A tsn_passdata
# FIRST MENU: generate a list of pass files, let the user select one
@@ -46,6 +47,7 @@ get_pass_files() {
tsn_passfile="$(printf "%s\n" "${tmp_pass_files[@]}" \
| "$dmenu_backend" "${dmenu_backend_opts[@]}")"
+ _EXIT_STATUS="$?"
if ! [[ -f "$tmp_prefix/$tsn_passfile".gpg ]]; then
_die
@@ -103,6 +105,7 @@ get_gopass_files() {
# the actual menu
tsn_passfile="$(printf "%s\n" "${!tmp_gopass_files[@]}" \
| "$dmenu_backend" "${dmenu_backend_opts[@]}")"
+ _EXIT_STATUS="$?"
if [[ -z $tsn_passfile ]]; then
_die
@@ -217,6 +220,20 @@ get_pass_data() {
unset -v passdata keyval_regex otp_regex idx key val
}
+# map custom actions to specific dmenu exit codes
+custom_keyb_action() {
+ case "$_EXIT_STATUS" in
+ 10) auto_type_def ;;
+ 11) auto_type "$tsn_username" ;;
+ 12) auto_type "$tsn_password" ;;
+ 13) key_open_url ;;
+ 14) wld_copy "$tsn_username" ;;
+ 15) wld_copy "$tsn_password" ;;
+ 16) wld_copy "$tsn_url" ;;
+ *) _die "unmapped exit code detected" ;;
+ esac
+}
+
# SECOND MENU: show a list of possible keys to choose from for autotyping or
# copying, depending on the value of tsn_action
# THIRD MENU: optional, this will show up if tsn_action is blank
@@ -863,6 +880,10 @@ main() {
get_gopass_files
fi
get_pass_data
+ if [[ $_EXIT_STATUS -ge 10 ]]; then
+ custom_keyb_action
+ exit 0
+ fi
key_menu
trap - EXIT TERM INT
}