From 39da53ab62b710a231cef8cea50bfa316816f2ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 18 Sep 2017 21:04:04 +0200 Subject: Add completions for usbkey --- bash_completions/usbkey | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bash_completions/usbkey (limited to 'bash_completions/usbkey') diff --git a/bash_completions/usbkey b/bash_completions/usbkey new file mode 100644 index 0000000..10cb0b9 --- /dev/null +++ b/bash_completions/usbkey @@ -0,0 +1,35 @@ +# Bash completion file for usbkey +# vim: ft=sh + +_usbkey_mounted() { + mount | grep "/media/usbkey" | grep -q "/dev/mapper/usbkey" +} + +_usbkey() { + local cur prev + _init_completion || return + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [[ $COMP_CWORD -gt 1 ]]; then + _usbkey_mounted || return + case "${COMP_WORDS[1]}" in + ssh-import) + [ -d "/media/usbkey/ssh" ] || return + local keys + for F in $(find "/media/usbkey/ssh" -name '*.pub'); do + F="${F#/media/usbkey/ssh/}" + keys="$keys ${F%.pub}" + done + COMPREPLY+=($(compgen -W "${keys}" -- ${cur})) + ;; + esac + else + local ops="-h --help mount sync" + if _usbkey_mounted; then + ops="$ops unmount ssh-list ssh-generate ssh-import" + fi + COMPREPLY+=($(compgen -W "${ops}" -- ${cur})) + fi +} + +complete -F _usbkey usbkey -- cgit v1.2.3