From d72b5a85814375e59466159c3d7ea81f6a093aa6 Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Wed, 18 Oct 2017 19:19:01 +0200 Subject: Add support for multiple roots These multiple roots can be given with --root (colon separated) and navigation is supported with Shift+Left and Shift+Right. --- README.md | 2 +- rofi-pass | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3ae89b0..88a2b91 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ addpass --name "My new Site" +user "zeltak" +branch "branch" +custom "foobar" +a * First argument `--name` is mandatory. This will be the filename of the new password entry. * Second argument can be `--root` followed by absolute path to your password-store. addpass also uses root config setting from rofi-pass config file. If both are not found, PASSWORD_STORE_DIR variable is checked. If none of the above are found, the default location `$HOME/.password-store` is used. - +* `--root` can also be a colon separated list of directories, in which case you can navigate between them on the main menu with Shift+Left and Shift+Right. * Fieldnames are defined with `+` and the actual value is defined inside the quotations. You can add as many fields as you like Also included is an import script for keepass2 databases. It's the same script that can be downloaded from the pass homepage, with some minor modifications to match rofi-pass structure. diff --git a/rofi-pass b/rofi-pass index a35cde9..3340995 100755 --- a/rofi-pass +++ b/rofi-pass @@ -42,6 +42,8 @@ type_menu="Alt+t" help="Alt+h" switch="Alt+x" insert_pass="Alt+n" +previous_root="Shift+Left" +next_root="Shift+Right" # Safe permissions umask 077 @@ -280,13 +282,17 @@ Run ${default_do} with Enter. For more help hit -kb-custom-7 "${show}" -kb-custom-8 "${copy_url}" -kb-custom-9 "${type_menu}" + -kb-custom-10 "${previous_root}" + -kb-custom-11 "${next_root}" -kb-custom-14 "${action_menu}" -kb-custom-15 "${copy_menu}" -kb-custom-16 "${help}" -kb-custom-17 "${switch}" -kb-custom-18 "${insert_pass}" + -kb-mode-previous "" # These keyboard shortcut options are needed, because + -kb-mode-next "" # Shift+ are otherwise taken by rofi. -select $entry - -p "rofi-pass > ") + -p "rofi-pass($root) > ") if [[ $help_header == "true" ]] then @@ -351,6 +357,8 @@ Run ${default_do} with Enter. For more help hit 16) viewEntry;; 17) copyURL;; 18) export default_do="menu"; typeMenu;; + 19) roots_index=$(( (roots_index-1+roots_length) % roots_length)); root=${roots[$roots_index]}; mainMenu;; + 20) roots_index=$(( (roots_index+1) % roots_length)); root=${roots[$roots_index]}; mainMenu;; 23) actionMenu;; 24) copyMenu;; 25) unset selected_password; helpMenu;; @@ -385,7 +393,11 @@ ${copy_menu}: Copy Custom Field ${action_menu}: Edit, Move, Delete, Re-generate Submenu ${show}: Show Password File ${insert_pass}: Insert new Pass Entry -${switch}: Switch Pass/Bookmark Mode" | _rofi -dmenu -mesg "Hint: All hotkeys are configurable in config file" -p "Help > ") +${switch}: Switch Pass/Bookmark Mode +--- +${previous_root}: Switch to previous password store (--roots) +${next_root}: Switch to next password store (--roots) +" | _rofi -dmenu -mesg "Hint: All hotkeys are configurable in config file" -p "Help > ") help_val=$? if [[ $help_val -eq 1 ]]; then exit; else unset helptext; mainMenu; fi @@ -650,7 +662,7 @@ rofi-pass (Version: 1.6-git) Usage: --insert insert new entry to password store --manage edit/move/delete entries - --root set custom root directory + --root set custom root directories (colon separated) --last-used highlight last used item --show-last show details of last used Entry --bmarks run bookmarks Mode @@ -694,16 +706,19 @@ main () { # check if alternative root directory was given on commandline if [[ -r "$HOME/.cache/rofi-pass/last_used" ]] && [[ $1 == "--last-used" || $1 == "--show-last" ]]; then - export root; root=$(awk -F ': ' '{ print $1 }' "$HOME/.cache/rofi-pass/last_used") + roots=("$(awk -F ': ' '{ print $1 }' "$HOME/.cache/rofi-pass/last_used")") elif [[ -n "$2" && "$1" == "--root" ]]; then - export root="${2}" + IFS=: read -r -a roots <<< "$2" elif [[ -n $root ]]; then - export root="${root}" + roots=("${root}") elif [[ -n ${PASSWORD_STORE_DIR} ]]; then - export root=${PASSWORD_STORE_DIR} + roots=("${PASSWORD_STORE_DIR}") else - export root="$HOME/.password-store" + roots=("$HOME/.password-store") fi + roots_index=0 + roots_length=${#roots[@]} + export root=${roots[$roots_index]} export PASSWORD_STORE_DIR="${root}" case $1 in --insert) -- cgit