Completion files of extensions not working properly?
Simon Blum
simon.blum at posteo.org
Thu Dec 1 19:19:38 UTC 2022
Hello,
I'm new here, so let me know if there already is an ongoing discussion
on this topic or if I get anything wrong about this.
I noticed that some extensions for pass (like pass-update or pass-tomb)
provide completion files, which are poorly integrated in pass. This is
due to the fact, that completion files are loaded dynamically on demand.
For example in bash the file $BASHCOMPDIR/pass is loaded when you enter
"pass <TAB>". As the completion file for pass-update is stored in
$BASHCOMPDIR/pass-update it is not loaded unless you type "pass-update
<TAB>". The completion files in fish and zsh are handled in a similar
manner.
I'd like to suggest a fix for that issue. The completion files of pass
may automatically seek completion files of extensions and source them.
Enclosed you find a patch that provides that feature together with
example completion files for the extension pass-file.
Regards,
Simon Blum
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-automatically-source-extension-completion-files.patch
Type: text/x-patch
Size: 4778 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20221201/31e51c9e/attachment.bin>
-------------- next part --------------
# completion file for bash
PASSWORD_STORE_EXTENSION_COMMANDS+=("file")
__password_store_extension_complete_file() {
local cur="${COMP_WORDS[COMP_CWORD]}"
case "$COMP_CWORD" in
2)
COMPREPLY+=($(compgen -W "add get" -- ${cur}))
;;
3)
case "${COMP_WORDS[2]}" in
a|add)
COMPREPLY+=($(compgen -f ${cur}))
;;
g|get)
_pass_complete_entries 1
;;
esac
;;
4)
case "${COMP_WORDS[2]}" in
a|add)
_pass_complete_entries
;;
esac
;;
esac
}
-------------- next part --------------
#autoload
PASSWORD_STORE_EXTENSION_COMMANDS+=("file:add/get file to/from password-store")
__password_store_extension_complete_file () {
case "$CURRENT" in
2)
local -a subcommands
subcommands=(
"add:add file to password-store"
"get:get file from password-store"
)
_describe -t commands 'pass' subcommands
;;
3)
local cmd=${words[2]}
case "${cmd}" in
a|add)
_files
;;
g|get)
_pass_complete_entries
;;
esac
;;
4)
local cmd=${words[2]}
case "${cmd}" in
a|add)
_pass_complete_entries
;;
esac
;;
esac
}
unfunction $(basename $(print -P %x))
-------------- next part --------------
set -l PROG 'pass'
function __fish_pass-file_needs_command
set -l cmd (commandline -opc)
if [ (count $cmd) -eq 2 -a "$cmd[2]" = file ]
return 0
end
return 1
end
function __fish_pass-file_arg_nr_of_command
set -l cmd (commandline -opc)
set -l expected_length (math 2 + $argv[1])
if [ (count $cmd) -eq $expected_length -a "$cmd[2]" = "file" -a "$cmd[3]" = $argv[2] ]
return 0
end
return 1
end
complete -c $PROG -f -n '__fish_pass_needs_command' -a file -d 'Command: add/get file to/from password-store'
complete -c $PROG -f -n '__fish_pass-file_needs_command' -a add -d 'add file to password-store'
complete -c $PROG -n '__fish_pass-file_arg_nr_of_command 1 a'
complete -c $PROG -n '__fish_pass-file_arg_nr_of_command 1 add'
complete -c $PROG -f -n '__fish_pass-file_arg_nr_of_command 2 a' -a "(__fish_pass_print_entries)"
complete -c $PROG -f -n '__fish_pass-file_arg_nr_of_command 2 add' -a "(__fish_pass_print_entries)"
complete -c $PROG -f -n '__fish_pass-file_needs_command' -a get -d 'get file from password-store'
complete -c $PROG -f -n '__fish_pass-file_arg_nr_of_command 1 g' -a "(__fish_pass_print_entries)"
complete -c $PROG -f -n '__fish_pass-file_arg_nr_of_command 1 get' -a "(__fish_pass_print_entries)"
More information about the Password-Store
mailing list