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

Re: Cryptsetup completion



On 6/2/20, Paul Ruane <paul.ruane@xxxxxxxxxx> wrote:
> Hi,
>
> For my own system I have modified the Zsh completion of cryptsetup to
> include completion of the hash and cipher based upon those declared
> available in /proc/crypto. I thought this might be useful for other
> users, too, so I have included my changes below for your
> consideration.
>
> 11,12c11,12
> <   '(-c --cipher)'{-c+,--cipher=}'[set cipher]:cipher specification' \
> <   '(-h --hash)'{-h+,--hash=}'[hash algorithm]:hash algorithm' \
> ---
>>   '(-c --cipher)'{-c+,--cipher=}'[set cipher]:cipher
>> specification:_ciphers' \
>>   '(-h --hash)'{-h+,--hash=}'[hash algorithm]:hash algorithm:_hashes' \
> 157a158,183
>>
>> _ciphers() {
>> typeset -a cipher_list
>> local line
>>
>> _call_program grep 'grep "^\(name\|type\)\s\+:" /proc/crypto | grep -B1
>> "^type\s\+:\s\+cipher" | grep "^name\s\+:" | cut -d ":" -f 2 | uniq | sed
>> "s/^ //"' | \
>> while read -A line
>> do
>> cipher_list+=($line[1])
>> done
>>
>> _describe -t ciphers 'cipher' cipher_list "$@"
>> }
>>
>> _hashes() {
>> typeset -a hash_list
>> local line
>>
>> _call_program grep 'grep "^\(name\|type\)\s\+:" /proc/crypto | grep -B1
>> "^type\s\+:\s\+shash" | grep "^name\s\+:" | cut -d ":" -f 2 | uniq | sed
>> "s/^ //"' | \
>> while read -A line
>> do
>> hash_list+=($line[1])
>> done
>>
>> _describe -t hashes 'hash' hash_list "$@"
>> }

One could also imagine these substitutions instead of forking twelve times:
cipher_list=( ${${${(M)${(s:name:)${(M)${(f)"$(</proc/crypto)"}:#(name|type)*}}:#*
cipher*}#*: }%% *} )
hash_list=( ${${${(M)${(s:name:)${(M)${(f)"$(</proc/crypto)"}:#(name|type)*}}:#*
shash*}#*: }%% *} )

-- 
Mikael Magnusson



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