Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: _cryptsetup



Hi,
here is a completion file for cryptsetup. As, I included luks (linux unified 
key setup) command, I have put it in Linux directory.


Index: Completion/Linux/_cryptsetup
===================================================================
RCS file: Completion/Linux/_cryptsetup
diff -N Completion/Linux/_cryptsetup
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Linux/_cryptsetup	9 Dec 2008 18:46:05 -0000
@@ -0,0 +1,125 @@
+#compdef cryptsetup
+
+_cryptsetup () {
+    emulate -L zsh
+    setopt extendedglob
+
+    local -a arguments
+    local state cmds
+
+    # hardcode list of password hashes accepted by gcrypt
+    local -a gcrypthash
+    gcrypthash=("sha1" "md5" "sha256" "ripemd160" "rmd160" "sha384" "sha512" "sha224" "md2" "md4" "tiger" "haval")
+
+    # read /proc/crypto to detect available ciphers
+    local -a ciphers
+    local cryptolines currentname
+    cryptolines=("${(f)$(< /proc/crypto )}")
+    for i in {0..${#cryptolines}}; do
+        if [[ $cryptolines[$i] == name[[:space:]]#*:[[:space:]]#(#b)(*) ]]; then
+            currentname=$match[1]
+        elif [[ $cryptolines[$i] == type[[:space:]]#*:[[:space:]]#cipher ]]; then
+            ciphers+=($currentname)
+        fi
+    done
+
+  _arguments \
+    '(--hash, -h)'{-h,--hash}'[hash for password hashing]:hash algorithm:($gcrypthash)' \
+    '(--cipher, -c)'{-c,--cipher}'[cipher specification]:cipher:($ciphers)' \
+    '(--verify-passphrase, -y)'{-y,--verify-passphrase}'[query for passwords twice]' \
+    '(--key-file, -d)'{-d,--key-file}'[use file as key material]:key file:_files' \
+    '(--key-slot, -S)'{-S,--key-slot}'[specify key slot for the new key]:key slot:' \
+    '(--key-size, -s)'{-s,--key-size}'[set key size in bits]:key size:' \
+    '(--size, -b)'{-b,--size}'[force size of underlying device in sectors]:device size:' \
+    '(--offset, -o)'{-o,--offset}'[start offset in the backend device]:start offset:' \
+    '(--skip, -p)'{-p,--skip}'[numbers of sectors of the encrypted data to skip at the beginning]:sectors number:' \
+    '--readonly[set up a read-only mapping]' \
+    '(--iter-time, -i)'{-i,--iter-time}'[milliseconds to spend with PBKDF2 password processing]:milliseconds number:' \
+    '(--batch-mode, -q)'{-q,--batch-mode}'[do not ask for confirmation]' \
+    '(--timeout, -t)'{-t,--timeout}'[number of seconds to wait before timeout]:seconds number:' \
+    '(--tries, -T)'{-T,--tries}'[How often the input of the passphrase shall be retried]:tries number:' \
+    '--align-payload=[Align payload at a boundary of value 512-byte sectors]:payload value:' \
+    '--version[Show the version]' \
+    '1: :->cmds' \
+    '*: :->args'
+
+  case $state in 
+    cmds)
+      cmds=(
+        'create:create a mapping'
+        'remove:remove an existing mapping'
+        'status:reports the status for a mapping'
+        'resize:resize an active mapping'
+        'luksFormat:initializes a LUKS partition'
+        'luksOpen:opens a LUKS partition'
+        'luksClose:closes a LUKS partition'
+        'luksAddKey:add a new key file/passphrase'
+        'luksRemoveKey:remove a key from LUKS devic'
+        'luksKillSlot:wipe a key from LUKS device'
+        'luksUUID:print UUID of device with LUKS header'
+        'isLuks:returns true if device has is LUKS partition. Otherwise, false'
+        'luksDump:dumps header infos of a LUKS partition'
+      )
+        _describe -t commands 'command' cmds
+      ;;
+      args)
+        args=()
+        case $line[1] in
+
+        create)
+         if [ ${#line} -eq 2 ]; then
+            _message 'name of mapping'
+        elif [ ${#line} -eq 3 ]; then
+            _arguments '*:device:_files'
+        fi
+        ;;
+
+        luksFormat)
+         if [ ${#line} -eq 2 ]; then
+            _arguments '*:device:_files'
+        elif [ ${#line} -eq 3 ]; then
+            _arguments '*:key file:_files'
+       fi
+        ;;
+
+        luksAddKey)
+         if [ ${#line} -eq 2 ]; then
+            _arguments '*:device:_files'
+        elif [ ${#line} -eq 3 ]; then
+            _arguments '*:new key file:_files'
+       fi
+        ;;
+
+        luksKillSlot)
+         if [ ${#line} -eq 2 ]; then
+            _arguments '*:device:_files'
+        elif [ ${#line} -eq 3 ]; then
+            _message 'key slot number'
+       fi
+        ;;
+
+        luksOpen)
+         if [ ${#line} -eq 2 ]; then
+            _arguments '*:device:_files'
+        elif [ ${#line} -eq 3 ]; then
+            _message 'name of mapping'
+        fi
+        ;;
+
+        luksUUID|isLuks|luksDump)
+            _arguments '*:device:_files'
+        ;;
+
+        remove|status|resize|luksClose)
+            local -a res
+            res=(/dev/mapper/*(:t))
+            _wanted name expl 'mapping name' compadd "$@" -a - res
+        ;;
+        esac
+    ;;
+  esac
+
+}
+
+
+_cryptsetup "$@"

Attachment: signature.asc
Description: Digital signature



Messages sorted by: Reverse Date, Date, Thread, Author