aboutsummaryrefslogtreecommitdiff
path: root/ssh-agent-filter.bash-completion
blob: 61debb933675180c60b3c710cd427a73ed30612f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# bash completion for ssh-agent-filter and afssh
#
# Copyright (C) 2013 Timo Weingärtner <timo@tiwe.de>
#
# This file is part of ssh-agent-filter.
#
# ssh-agent-filter is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ssh-agent-filter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ssh-agent-filter.  If not, see <http://www.gnu.org/licenses/>.

_ssh-agent-filter () {
	local cur prev words cword opts
	_init_completion -n : || return

	_quote_readline_by_ref "$cur" cur
	
	opts="--all-confirmed --comment --comment-confirmed --debug --fingerprint --fingerprint-confirmed --help --key --key-confirmed --name --version"
	
	case "$prev" in
		-c|--comment|-C|--comment-confirmed)
			# 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|-F|--fingerprint-confirmed)
			# 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|-K|--key-confirmed)
			# this is base64, no quoting needed
			local keys="$(ssh-add -L | cut -d\  -f2 )"
			COMPREPLY=( $(compgen -W "$keys" -- "$cur") )
			return 0
			;;
		-n|--name)
			COMPREPLY=( $(compgen -W "" -- "$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: