/
truecrypt.bash-completion
75 lines (65 loc) · 3.31 KB
/
truecrypt.bash-completion
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
# https://launchpad.net/~stefansundin/+archive/ubuntu/truecrypt
# Notes:
# This script does not support having an equal sign in COMP_WORDBREAKS.
# We only help complete the first value on comma separated lists (e.g. --fs-options).
# Arguments with equal signs need their value without a space. We don't automatically add spaces to these arguments.
# Bugs in TrueCrypt's documentation:
# All the options that take VOLUME_PATH or FILE_PATH actually takes it as the next argument, NOT after an equal sign!
# --auto-mount can take a comma separated list, i.e. mount both devices and favorites at the same time.
_truecrypt_complete() {
COMPREPLY=( $( compgen -W "$1" -- "$cur" ))
}
_truecrypt_opt() {
COMPREPLY=( $( compgen -W "$1" -P "$opt=" -- "$val" ))
}
_truecrypt() {
COMPREPLY=()
local COMP_FILEDIR_FALLBACK=1
local cur prev opt val
_get_comp_words_by_ref cur prev
if [[ $cur == --?*=* ]]; then
opt="${cur%%?(\\)=*}"
val="${cur#*=}"
fi
if [[ $prev == --create-filedir ]]; then
# --create-keyfile argument does not need to be a .tc file
_filedir
elif [[ $opt =~ ^--(new-|protection-)?keyfiles|--random-source$ ]]; then
# We have to do some hacks here for _filedir to work after an equal sign.
cur="${cur/#--*=/}"
compopt -o nospace
_filedir
COMPREPLY=("${COMPREPLY[@]/#/$opt=}")
elif [[ $opt == --auto-mount ]]; then
_truecrypt_opt "devices favorites"
elif [[ $opt == --encryption ]]; then
_truecrypt_opt "aes serpent twofish aes-twofish aes-twofish-serpent serpent-aes serpent-twofish-aes twofish-serpent"
elif [[ $opt == --filesystem ]]; then
_truecrypt_opt "none fat ext2 ext3 ext4"
elif [[ $opt == --fs-options ]]; then
# These are just some common mount options, not an exhaustive list.
_truecrypt_opt "async auto defaults exec loop noauto noexec nouser remount ro rw user"
elif [[ $opt == --hash ]]; then
_truecrypt_opt "ripemd-160 sha-512 whirlpool"
elif [[ $opt == --mount-options ]]; then
_truecrypt_opt "headerbak nokernelcrypto readonly system timestamp"
elif [[ $opt == --protect-hidden ]]; then
_truecrypt_opt "yes no"
elif [[ $opt == --slot ]]; then
_truecrypt_opt "1 64"
elif [[ $opt == --volume-type ]]; then
_truecrypt_opt "normal hidden"
elif [[ $opt == --token-lib ]]; then
_truecrypt_opt "/usr/lib/i386-linux-gnu/opensc-pkcs11.so /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so"
elif [[ $cur =~ ^- ]]; then
_truecrypt_complete "--background-task -c --create -C -d --delete-token-keyfiles --explore --export-token-keyfile -f --force -h --help --import-token-keyfiles -l --list --list-token-keyfiles --load-preferences --mount --save-preferences --test --version --display-password -k -m --non-interactive -p --quick -t --text -v --verbose --backup-headers --create-keyfile --change --dismount --restore-headers --volume-properties --auto-mount= --encryption= --filesystem= --fs-options= --hash= --keyfiles= --mount-options= --new-keyfiles= --new-password= --password= --protect-hidden= --protection-keyfiles= --protection-password= --random-source= --slot= --size= --token-lib= --volume-type="
else
_filedir tc
fi
# Don't put a space after an argument that needs value after equal sign.
if [[ ${#COMPREPLY[@]} == 1 && "${COMPREPLY[@]}" == *= ]]; then
compopt -o nospace
fi
return 0
}
complete -F _truecrypt truecrypt