Shell completions
parent
89be84860d
commit
dbd4563e77
@ -0,0 +1,63 @@
|
||||
#/usr/bin/env bash
|
||||
|
||||
_remove_opts() {
|
||||
local opt new_opts
|
||||
for opt in ${available_opts}; do
|
||||
if [[ $opt != $1 && $opt != $2 ]]; then
|
||||
new_opts+="$opt "
|
||||
fi
|
||||
done
|
||||
available_opts=$new_opts
|
||||
}
|
||||
|
||||
_doby_completion() {
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local opts="-f --force-encrypt -i --interactive -h --help -V --version --password -t --time-cost -m --memory-cost -p --parallelism -b --block-size -c --cipher"
|
||||
if [[ ${cur} == -* ]]; then
|
||||
local i available_opts=$opts
|
||||
for i in ${COMP_WORDS[@]}; do
|
||||
if [[ ${opts[*]} =~ $i ]]; then
|
||||
case $i in
|
||||
"-f"|"--force-encrypt")
|
||||
_remove_opts "-f" "--force-encrypt"
|
||||
;;
|
||||
"-i"|"--interactive")
|
||||
_remove_opts "-i" "--interactive"
|
||||
;;
|
||||
"-h"|"--help")
|
||||
_remove_opts "-h" "--help"
|
||||
;;
|
||||
"-V"|"--version")
|
||||
_remove_opts "-V" "--version"
|
||||
;;
|
||||
"--password")
|
||||
_remove_opts "--password"
|
||||
;;
|
||||
"-t"|"--time-cost")
|
||||
_remove_opts "-t" "--time-cost"
|
||||
;;
|
||||
"-m"|"--memory-cost")
|
||||
_remove_opts "-m" "--memory-cost"
|
||||
;;
|
||||
"-p"|"--parallelism")
|
||||
_remove_opts "-p" "--parallelism"
|
||||
;;
|
||||
"-b"|"--block-size")
|
||||
_remove_opts "-b" "--block-size"
|
||||
;;
|
||||
"-c"|"--cipher")
|
||||
_remove_opts "-c" "--cipher"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
COMPREPLY=($(compgen -W "${available_opts}" -- "${cur}"))
|
||||
else
|
||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
if [[ ${prev} == "-c" || ${prev} == "--cipher" ]]; then
|
||||
COMPREPLY=($(compgen -W "aes xchacha20" -- "${cur}"))
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _doby_completion -o bashdefault -o default doby
|
@ -0,0 +1,19 @@
|
||||
#compdef doby
|
||||
|
||||
function _doby {
|
||||
_arguments \
|
||||
'(-f --force-encrypt)'{-f,--force-encrypt}'[Encrypt even if doby format is recognized]' \
|
||||
'(-i --interactive)'{-i,--interactive}'[Prompt before overwriting files]' \
|
||||
'(: * -)'{-h,--help}'[Prints help information]' \
|
||||
'(: * -)'{-V,--version}'[Prints version information]' \
|
||||
'--password=[Password used to derive encryption keys]' \
|
||||
'(-t --time-cost)'{-t,--time-cost}'[Argon2 time cost]' \
|
||||
'(-m --memory-cost)'{-m,--memory-cost}'[Argon2 memory cost (in kilobytes)]' \
|
||||
'(-p --parallelism)'{-p,--parallelism}'[Argon2 parallelism cost]' \
|
||||
'(-b --block-size)'{-b,--block-size}'[Size of the I/O buffer (in bytes)]' \
|
||||
'(-c --cipher)'{-c,--cipher}'[Encryption cipher to use]: :(aes xchacha20)' \
|
||||
':::_files' \
|
||||
':::_files' \
|
||||
}
|
||||
|
||||
_doby "$@"
|
@ -0,0 +1,17 @@
|
||||
use std::{env, io};
|
||||
use clap::Shell;
|
||||
use doby::cli;
|
||||
|
||||
fn main() {
|
||||
let mut args = env::args().skip(1);
|
||||
if let Some(shell) = args.next() {
|
||||
if let Ok(shell) = shell.parse() {
|
||||
cli::app().gen_completions_to("doby", shell, &mut io::stdout());
|
||||
} else {
|
||||
eprintln!("error: invalid shell: {}", shell);
|
||||
eprintln!("shell variants: {:?}", Shell::variants());
|
||||
}
|
||||
} else {
|
||||
eprintln!("usage: compgen <shell>");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue