aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2013-08-31 16:07:56 +0200
committerTimo Weingärtner <timo@tiwe.de>2013-08-31 18:18:30 +0200
commit84ab40ff5fc9d19066c579fce94cd6c24d1d3b90 (patch)
tree540ae366b0825cb557ebe490235d0401a45ac1cb
parent9826dce1feec00b2759eb91c771068a11e77a219 (diff)
downloadssh-agent-filter-84ab40ff5fc9d19066c579fce94cd6c24d1d3b90.tar.gz
add basic bash-completion
escaping of some special chars is not handled yet
-rw-r--r--ssh-agent-filter.bash-completion55
1 files changed, 55 insertions, 0 deletions
diff --git a/ssh-agent-filter.bash-completion b/ssh-agent-filter.bash-completion
new file mode 100644
index 0000000..c1080f6
--- /dev/null
+++ b/ssh-agent-filter.bash-completion
@@ -0,0 +1,55 @@
+_ssh-agent-filter () {
+ local cur prev words cword opts
+ _init_completion -n : || return
+
+ _quote_readline_by_ref "$cur" cur
+
+ opts="--comment --debug --fingerprint --help --key --version"
+
+ case "$prev" in
+ -c|--comment)
+ # hm, key comments might contain anything, how can I quote them ?
+ local comments="$(ssh-add -L | cut -d\ -f3- )"
+ COMPREPLY=( $(compgen -W "$comments" -- "$cur") )
+ return 0
+ ;;
+ -f|--fp|--fingerprint)
+ # fingerprints contain many colons
+ local fingerprints="$(ssh-add -l | cut -d\ -f2 )"
+ COMPREPLY=( $(compgen -W "$fingerprints" -- "$cur") )
+ __ltrim_colon_completions "$cur"
+ return 0
+ ;;
+ -k|--key)
+ # this is base64, no quoting needed
+ local keys="$(ssh-add -L | cut -d\ -f2 )"
+ COMPREPLY=( $(compgen -W "$keys" -- "$cur") )
+ return 0
+ ;;
+ esac
+
+ COMPREPLY=( $(compgen -W "$opts" -- "$cur") )
+ return 0
+} && complete -F _ssh-agent-filter ssh-agent-filter
+
+_ssh-agent-filter_have_dash-dash () {
+ local i
+ for (( i=0 ; i < cword ; i++ )) ; do
+ [ "${words[$i]}" = -- ] && return 0
+ done
+ return 1
+}
+
+_afssh () {
+ local cur prev words cword
+ _init_completion -n : || return
+
+ if _ssh-agent-filter_have_dash-dash; then
+ # complete ssh
+ _xfunc ssh _ssh
+ else
+ _ssh-agent-filter
+ fi
+} && complete -F _afssh afssh
+
+# vim:ft=sh: