Skip to content

Commit

Permalink
Add --keyring-backend argument completion for bash
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jul 28, 2023
1 parent ded96bf commit adbea86
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions keyring/backend_complete.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Complete keyring backends for `keyring -b` from `keyring --list-backends`
# # keyring -b <TAB>
# keyring.backends.chainer.ChainerBackend keyring.backends.fail.Keyring ...

_keyring_backends() {
local choices
choices=$(
"${COMP_WORDS[0]}" --list-backends 2>/dev/null |
while IFS=$' \t' read -r backend rest; do
printf "%s\n" "$backend"
done
)
compgen -W "${choices[*]}" -- "$1"
}
6 changes: 5 additions & 1 deletion keyring/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ def get_action(parser, option):

def install_completion(parser):
preamble = dict(
bash=files(__package__).joinpath('backend_complete.bash').read_text(),
zsh=files(__package__).joinpath('backend_complete.zsh').read_text(),
)
shtab.add_argument_to(parser, preamble=preamble)
get_action(parser, '--keyring-path').complete = shtab.DIR
get_action(parser, '--keyring-backend').complete = dict(zsh='backend_complete')
get_action(parser, '--keyring-backend').complete = dict(
bash='_keyring_backends',
zsh='backend_complete',
)
return parser


Expand Down

0 comments on commit adbea86

Please sign in to comment.