From 54af96bb309b256798e20cd1660c805dd37ecccb Mon Sep 17 00:00:00 2001 From: Coutinho de Souza Date: Thu, 28 Mar 2024 09:34:50 -0300 Subject: [PATCH] add autocomplete on unique match and PWD files completion for bash completion --- file.bash.completion | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/file.bash.completion b/file.bash.completion index f05758b..c7d0694 100644 --- a/file.bash.completion +++ b/file.bash.completion @@ -1,3 +1,4 @@ +#shellcheck disable=SC2207,SC2086,SC2155,SC2154 PASSWORD_STORE_EXTENSION_COMMANDS+=(file) __password_store_extension_complete_file() { @@ -5,11 +6,21 @@ __password_store_extension_complete_file() { local flags=(-h --help -v --version) if [[ "${COMP_CWORD}" -gt 2 ]]; then case "${COMP_WORDS[2]}" in - add | get) _pass_complete_entries ;; + get) _pass_complete_entries 1 ;; + add) + if [[ "${COMP_CWORD}" -gt 3 ]]; then + _pass_complete_entries 1 + else + local -a files + mapfile -t files <<<"$(compgen -f $PWD/${cur})" + if [[ -e "${files[0]}" ]]; then + COMPREPLY+=("${files[@]#"$PWD/"}") + fi + fi + ;; esac else - #shellcheck disable=SC2207,SC2086 COMPREPLY+=($(compgen -W "${commands[*]} ${flags[*]}" -- ${cur})) - _pass_complete_entries + _pass_complete_entries 1 fi }