From 39a82750e85da6c0503121f26ac24eb046c9b5de Mon Sep 17 00:00:00 2001 From: Christian Kohlstedde Date: Wed, 22 Jul 2020 21:48:16 +0200 Subject: [PATCH 1/5] Add editorconfig --- .editorconfig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f068930 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true + +indent_style = tab + +[Makefile] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false + +[*.py] +indent_style = space +indent_size = 4 From b286cea65dd55a4f45aa10a068461b344e39911a Mon Sep 17 00:00:00 2001 From: Christian Kohlstedde Date: Wed, 22 Jul 2020 22:05:54 +0200 Subject: [PATCH 2/5] Reindent with vim --- rofi-pass | 102 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/rofi-pass b/rofi-pass index 7dcd537..73364f5 100755 --- a/rofi-pass +++ b/rofi-pass @@ -70,7 +70,7 @@ has_qrencode() { # get all password files and create an array list_passwords() { cd "${root}" || exit - pw_list=($(find -L * -name "*.gpg")) + pw_list=($(find -L * -name "*.gpg")) printf '%s\n' "${pw_list[@]%.gpg}" | sort -n } @@ -102,7 +102,7 @@ autopass () { ":enter") xdotool key Return;; ":otp") printf '%s' "$(generateOTP)" | xdotool type --delay ${xdotool_delay} --clearmodifiers --file -;; "pass") printf '%s' "${password}" | xdotool type --delay ${xdotool_delay} --clearmodifiers --file -;; - "path") printf '%s' "${selected_password}" | rev | cut -d'/' -f1 | rev | xdotool type --clearmodifiers --file -;; + "path") printf '%s' "${selected_password}" | rev | cut -d'/' -f1 | rev | xdotool type --clearmodifiers --file -;; *) printf '%s' "${stuff[${word}]}" | xdotool type --delay ${xdotool_delay} --clearmodifiers --file -;; esac done @@ -266,7 +266,8 @@ viewEntry () { generatePass () { askmenu_content=( "Yes" - "No") + "No" + ) askGenMenu=$(printf '%s\n' "${askmenu_content[@]}" | _rofi -dmenu -p "Generate new Password for ${selected_password}? > ") askgen_exit=$? @@ -285,7 +286,8 @@ generatePass () { symbols_content=( "0 Cancel" "1 Yes" - "2 No") + "2 No" + ) symbols=$(printf '%s\n' "${symbols_content[@]}" | _rofi -dmenu -p "Use Symbols? > ") symbols_val=$? @@ -319,11 +321,11 @@ generatePass () { mainMenu () { if [[ $1 == "--bmarks" ]]; then selected_password="$(list_passwords 2>/dev/null \ - | _rofi -mesg "Bookmarks Mode. ${switch} to switch" \ - -dmenu \ - -kb-custom-10 "${switch}" \ - -select "$entry" \ - -p "rofi-pass > ")" + | _rofi -mesg "Bookmarks Mode. ${switch} to switch" \ + -dmenu \ + -kb-custom-10 "${switch}" \ + -select "$entry" \ + -p "rofi-pass > ")" rofi_exit=$? @@ -354,11 +356,12 @@ mainMenu () { -kb-custom-16 "${help}" -kb-custom-17 "${switch}" -kb-custom-18 "${insert_pass}" - -kb-custom-19 "${qrcode}") - args+=(-kb-mode-previous "" # These keyboard shortcut options are needed, because - -kb-mode-next "" # Shift+ are otherwise taken by rofi. - -select "$entry" - -p "> ") + -kb-custom-19 "${qrcode}" + ) + args+=( -kb-mode-previous "" # These keyboard shortcut options are needed, because + -kb-mode-next "" # Shift+ are otherwise taken by rofi. + -select "$entry" + -p "> " ) if [[ ${#roots[@]} -gt "1" || $custom_root == "true" ]]; then args+=(-mesg "PW Store: ${root}") @@ -404,7 +407,7 @@ mainMenu () { *) _id="${LINE%%: *}" _val="${LINE#* }" - ;; + ;; esac if [[ -n "$_id" ]]; then @@ -428,10 +431,10 @@ mainMenu () { if [[ -z "${stuff["${USERNAME_field}"]}" ]]; then if [[ -n $default_user ]]; then if [[ "$default_user" == ":filename" ]]; then - stuff["${USERNAME_field}"]="$(basename $selected_password)" - else - stuff["${USERNAME_field}"]="${default_user}" - fi + stuff["${USERNAME_field}"]="$(basename $selected_password)" + else + stuff["${USERNAME_field}"]="${default_user}" + fi fi fi pass_content="$(for key in "${!stuff[@]}"; do printf '%s\n' "${key}: ${stuff[$key]}"; done)" @@ -470,23 +473,23 @@ clearUp () { helpMenu () { printf '%s' "${autotype}: Autotype -${type_user}: Type Username -${type_pass}: Type Password -${qrcode}: Generate and display qrcode ---- -${copy_name}: Copy Username -${copy_pass}: Copy Password -${copy_url}: Copy URL -${open_url}: Open URL -${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 ---- -${previous_root}: Switch to previous password store (--root) -${next_root}: Switch to next password store (--root) + ${type_user}: Type Username + ${type_pass}: Type Password + ${qrcode}: Generate and display qrcode + --- + ${copy_name}: Copy Username + ${copy_pass}: Copy Password + ${copy_url}: Copy URL + ${open_url}: Open URL + ${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 + --- + ${previous_root}: Switch to previous password store (--root) + ${next_root}: Switch to next password store (--root) " | _rofi -dmenu -mesg "Hint: All hotkeys are configurable in config file" -p "Help > " help_val=$? @@ -547,7 +550,8 @@ actionMenu () { "2 Copy Password File" "3 Delete Password File" "4 Edit Password File" - "5 Generate New Password") + "5 Generate New Password" + ) action=$(printf '%s\n' "${action_content[@]}" | _rofi -dmenu -p "Choose Action > ") if [[ ${action} == "1 Move Password File" ]]; then @@ -592,7 +596,8 @@ showEntry () { fi bla_content=("< Return" - "${pass_content}") + "${pass_content}" + ) bla=$(printf '%s\n' "${bla_content[@]}" | _rofi -dmenu -mesg "Enter: Copy entry to clipboard" -p "> ") rofi_exit=$? @@ -657,7 +662,8 @@ manageEntry () { elif [[ "$1" == "delete" ]]; then HELP="Selected entry: ${selected_password}" ask_content=("Yes" - "No") + "No" + ) ask=$(printf '%s\n' "${ask_content[@]}" | _rofi -mesg "${HELP}" -dmenu -p "Are You Sure? > ") if [[ "$ask" == "Yes" ]]; then PASSWORD_STORE_DIR="${root}" pass rm --force "${selected_password}" @@ -700,7 +706,8 @@ insertPass () { user_content=("${default_user2}" "${USER}" - "${default_user}") + "${default_user}" + ) user=$(printf '%s\n' "${user_content[@]}" | _rofi -dmenu -mesg "Chose Username or type" -p "> ") val=$? @@ -711,7 +718,8 @@ insertPass () { group_content=("No Group" "---" - "${grouplist}") + "${grouplist}" + ) group=$(printf '%s\n' "${group_content[@]}" | _rofi -dmenu -p "Choose Group > ") val=$? @@ -733,12 +741,14 @@ insertPass () { pass_content=("${pw}" "---" "${USERNAME_field}: ${user}" - "${URL_field}: ${url}") + "${URL_field}: ${url}" + ) printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${name}" > /dev/null && PASSWORD_STORE_DIR="${root}" pass edit "${name}" else pass_content=("${pw}" "---" - "${USERNAME_field}: ${user}") + "${USERNAME_field}: ${user}" + ) printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${name}" > /dev/null && PASSWORD_STORE_DIR="${root}" pass edit "${name}" fi else @@ -746,12 +756,14 @@ insertPass () { pass_content=("${pw}" "---" "${USERNAME_field}: ${user}" - "${URL_field}: ${url}") + "${URL_field}: ${url}" + ) printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${name}" > /dev/null && PASSWORD_STORE_DIR="${root}" pass edit "${group}/${name}" else pass_content=("${pw}" "---" - "${USERNAME_field}: ${user}") + "${USERNAME_field}: ${user}" + ) printf '%s\n' "${pass_content[@]}" | PASSWORD_STORE_DIR="${root}" pass insert -m "${group}/${name}" > /dev/null if [[ $edit_new_pass == "true" ]]; then PASSWORD_STORE_DIR="${root}" pass edit "${group}/${name}" From a201b04125a5b7b020b9d2010f8791cc810c33bb Mon Sep 17 00:00:00 2001 From: Christian Kohlstedde Date: Wed, 22 Jul 2020 22:09:27 +0200 Subject: [PATCH 3/5] Fix help with heredoc statement --- rofi-pass | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/rofi-pass b/rofi-pass index 73364f5..21a14ee 100755 --- a/rofi-pass +++ b/rofi-pass @@ -472,7 +472,8 @@ clearUp () { } helpMenu () { - printf '%s' "${autotype}: Autotype + _rofi -dmenu -mesg "Hint: All hotkeys are configurable in config file" -p "Help > " <<- EOM + ${autotype}: Autotype ${type_user}: Type Username ${type_pass}: Type Password ${qrcode}: Generate and display qrcode @@ -490,14 +491,14 @@ helpMenu () { --- ${previous_root}: Switch to previous password store (--root) ${next_root}: Switch to next password store (--root) - " | _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 +EOM +help_val=$? + +if [[ $help_val -eq 1 ]]; then + exit; +else + unset helptext; mainMenu; +fi } From 546200bf0b250af92e893533e495254b17f40c57 Mon Sep 17 00:00:00 2001 From: Christian Kohlstedde Date: Wed, 22 Jul 2020 22:37:28 +0200 Subject: [PATCH 4/5] Fix password listing regression (#179) --- README.md | 1 + rofi-pass | 20 ++++++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3d1f7a6..fec1ffc 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ in a convenient way using [rofi](https://github.com/DaveDavenport/rofi). * xdotool * gawk * bash 4.x +* find * pwgen * [pass-otp](https://github.com/tadfisher/pass-otp) (optional: for OTPs) diff --git a/rofi-pass b/rofi-pass index 21a14ee..96a3072 100755 --- a/rofi-pass +++ b/rofi-pass @@ -67,12 +67,17 @@ has_qrencode() { command -v qrencode >/dev/null 2>&1 } -# get all password files and create an array +listgpg () { + mapfile -d '' pw_list < <(find -L . -name '*.gpg' -print0) + pw_list=("${pw_list[@]#./}") + printf '%s\n' "${pw_list[@]}" | sort -n +} + +# get all password files and output as newline-delimited text list_passwords() { cd "${root}" || exit - pw_list=($(find -L * -name "*.gpg")) + mapfile -t pw_list < <(listgpg) printf '%s\n' "${pw_list[@]%.gpg}" | sort -n - } doClip () { @@ -678,11 +683,6 @@ manageEntry () { fi } -listgpg () { - pw_list=(**/*.gpg) - printf '%s\n' "${pw_list[@]}" | sort -n -} - insertPass () { url=$(xclip --selection clipboard -o) @@ -805,9 +805,6 @@ get_config_file () { } main () { - # enable extended globbing - shopt -s nullglob globstar - # load config file config_file="$(get_config_file)" [[ ! -z "$config_file" ]] && source "$config_file" @@ -881,4 +878,3 @@ main () { } main "$@" - From 527bb3b3ac2186c4a1181c41d53fd7bef7693d66 Mon Sep 17 00:00:00 2001 From: Christian Kohlstedde Date: Wed, 22 Jul 2020 22:43:56 +0200 Subject: [PATCH 5/5] Fix shellcheck warnings --- rofi-pass | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rofi-pass b/rofi-pass index 96a3072..22667e2 100755 --- a/rofi-pass +++ b/rofi-pass @@ -436,7 +436,7 @@ mainMenu () { if [[ -z "${stuff["${USERNAME_field}"]}" ]]; then if [[ -n $default_user ]]; then if [[ "$default_user" == ":filename" ]]; then - stuff["${USERNAME_field}"]="$(basename $selected_password)" + stuff["${USERNAME_field}"]="$(basename "$selected_password")" else stuff["${USERNAME_field}"]="${default_user}" fi @@ -796,8 +796,8 @@ get_config_file () { # return the first config file with a valid path for config in "${configs[@]}"; do - # '! -z' is needed in case ROFI_PASS_CONFIG is not set - if [[ ! -z "${config}" && -f "${config}" ]]; then + # '-n' is needed in case ROFI_PASS_CONFIG is not set + if [[ -n "${config}" && -f "${config}" ]]; then printf "%s" "$config" return fi @@ -807,7 +807,7 @@ get_config_file () { main () { # load config file config_file="$(get_config_file)" - [[ ! -z "$config_file" ]] && source "$config_file" + [[ -n "$config_file" ]] && source "$config_file" # create tmp dir if [[ ! -d "$cache_dir/rofi-pass" ]]; then