From 7df1e2de504f28574230ee214550aefa717f8476 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 6 Apr 2014 04:51:48 -0400 Subject: bash-completion: complete the new init -p switch. --- src/completion/pass.bash-completion | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/completion/pass.bash-completion b/src/completion/pass.bash-completion index d0ef012..c6a2f4b 100644 --- a/src/completion/pass.bash-completion +++ b/src/completion/pass.bash-completion @@ -1,6 +1,6 @@ # completion file for bash -# Copyright (C) 2012 Jason A. Donenfeld and +# Copyright (C) 2012 - 2014 Jason A. Donenfeld and # Brian Mattern . All Rights Reserved. # This file is licensed under the GPLv2+. Please see COPYING for more information. @@ -12,9 +12,7 @@ _pass_complete_entries () { local IFS=$'\n' local items=($(compgen -f $prefix$cur)) for item in ${items[@]}; do - if [[ $item == $prefix.* ]]; then - continue - fi + [[ $item == $prefix.* ]] && continue # if there is a unique match, and it is a directory with one entry # autocomplete the subentry as well (recursively) @@ -37,6 +35,17 @@ _pass_complete_entries () { done } +_pass_complete_folders () { + prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}" + + local IFS=$'\n' + local items=($(compgen -d $prefix$cur)) + for item in ${items[@]}; do + [[ $item == $prefix.* ]] && continue + COMPREPLY+=("${item#$prefix}/") + done +} + _pass_complete_keys () { local IFS=$'\n' # Extract names and email addresses from gpg --list-keys @@ -52,8 +61,12 @@ _pass() if [[ $COMP_CWORD -gt 1 ]]; then case "${COMP_WORDS[1]}" in init) - COMPREPLY+=($(compgen -W "-e --reencrypt" -- ${cur})) - _pass_complete_keys + COMPREPLY+=($(compgen -W "-e --reencrypt -p --path" -- ${cur})) + if [[ ${COMP_WORDS[$COMP_CWORD-1]} == "-p" || ${COMP_WORDS[$COMP_CWORD-1]} == "--path" ]]; then + _pass_complete_folders + else + _pass_complete_keys + fi ;; ls|list|edit) _pass_complete_entries -- cgit v1.2.3