aboutsummaryrefslogtreecommitdiff
path: root/zsh_completions/usbkey
blob: eada8f69e7a5e45326d4c3e486f7caee835450d0 (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
#compdef usbkey
#autoload

_usbkey_mounted() {
	mount | grep "/media/usbkey" | grep -q "/dev/mapper/usbkey"
}

_usbkey () {
	local cmd
	if (( CURRENT > 2)); then
		_usbkey_mounted || return
		operation=${words[2]}
		# Run the completion for the subcommand
		case "${operation}" 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+=("${F%.pub}")
				done
				_describe -t keys 'usbkey' keys
				;;
			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+=("${F%.crt}")
				done
				_describe -t certificates 'usbkey' certs
				;;
			# TODO
		esac
	else
		local operations=(
			"mount:Mount key of usb driver"
			"unmount:Unmount usb driver"
			"sync:Synchronize drive to bakup drive"
		)
		if _usbkey_mounted; then
			operations+=(
				"gpg-import:Import gpg key"
				"ssh-import:Import ssh key"
				"ssh-generate:Generate new ssh key"
				"ssh-list:List all SSH keys in store"
				"openvpn-list:List all OpenVPN keys"
				"openvpn-get:Get OpenVPN keys for some host"
				"openvpn-generate:Generate OpenVPN key for new host"
			)
		fi
		_describe -t operations 'usbkey' operations
		_arguments : "--help[Output help message]"
	fi
}

_usbkey