From: Gustav Eek Date: Thu, 22 Oct 2020 22:23:15 +0000 (+0200) Subject: [mosh] Inital on mosh bash completion X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=ba23a0be9c6613d04d19d04e549dceea31af7678;p=users%2Fgustav%2Fscripts.git [mosh] Inital on mosh bash completion --- diff --git a/bash_completion.d/mosh b/bash_completion.d/mosh new file mode 100644 index 0000000..238c317 --- /dev/null +++ b/bash_completion.d/mosh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# This file provides programmable completion for repo-encrypt under +# the bash shell + +function _mosh { + + local cmd cur prev line subcmds opts + COMPREPLY=() + cmd="${1##*/}" + cur="${COMP_WORDS[COMP_CWORD]}" # called 'cur' by convention [1] + prev="${COMP_WORDS[COMP_CWORD-1]}" + line="${COMP_LINE}" + subcmds="encrypt decrypt" + opts="--help" + + if [[ "$COMP_CWORD" == 1 ]]; then + COMPREPLY=($(compgen -W "${subcmds} ${opts}" -- "${cur}")) + return 0 + elif [[ ${COMP_WORDS[1]} == "--help" ]]; then + COMPREPLY=(" ") # none empty + >&2 printf "\n${cmd}: No completion on '--help'" + return 0 + fi + + return 0 +} + +complete -o filenames -o default -F _repo-encrypt repo-encrypt # There are details [2] + +# cat ~/.ssh/config | sed -n '/^[[:space:]]*[Hh]ost/ {s/#.*$//g; s/\*//g; s/[Hh]ost\([Nn]ame\)*//g; s/[[:space:]]/\n/g; p}' |sort -u | less + +# [1]: http://tldp.org/LDP/abs/html/tabexpansion.html +# [2]: http://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion