]> git.g-eek.se Git - users/gustav/scripts.git/commitdiff
[mosh] Inital on mosh bash completion
authorGustav Eek <gustav.eek@fripost.org>
Thu, 22 Oct 2020 22:23:15 +0000 (00:23 +0200)
committerGustav Eek <gustav.eek@fripost.org>
Thu, 22 Oct 2020 22:23:15 +0000 (00:23 +0200)
bash_completion.d/mosh [new file with mode: 0644]

diff --git a/bash_completion.d/mosh b/bash_completion.d/mosh
new file mode 100644 (file)
index 0000000..238c317
--- /dev/null
@@ -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