aboutsummaryrefslogtreecommitdiff
path: root/bash_completions/usbkey
blob: 10cb0b9b1f16e09f27b0551620c31cfec7d34bcc (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
# 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}))
				;;
		esac
	else
		local ops="-h --help mount sync"
		if _usbkey_mounted; then
			ops="$ops unmount ssh-list ssh-generate ssh-import"
		fi
		COMPREPLY+=($(compgen -W "${ops}" -- ${cur}))
	fi
}

complete -F _usbkey usbkey