aboutsummaryrefslogtreecommitdiff
path: root/bash_completions/usbkey
blob: acd6877dfdadf842cb6683eae2f634ede8b5014a (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
# 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}))
				;;
			openvpn-get)
				[ -d "/media/usbkey/openvpn" ] || return
				local certs
				for F in $(find "/media/usbkey/openvpn" -name 'ca.crt' -o -name '*.crt' -print); do
					F="${F#/media/usbkey/openvpn/}"
					certs="$certs ${F%.crt}"
				done
				COMPREPLY+=($(compgen -W "${certs}" -- ${cur}))
				;;
		esac
	else
		local ops="-h --help mount sync"
		if _usbkey_mounted; then
			ops="$ops unmount gpg-import ssh-list ssh-generate ssh-import openvpn-list openvpn-get openvpn-generate"
		fi
		COMPREPLY+=($(compgen -W "${ops}" -- ${cur}))
	fi
}

complete -F _usbkey usbkey