From 02205ebca7d8e63c477c44c61a9be59e4527b329 Mon Sep 17 00:00:00 2001 From: NRK Date: Tue, 28 May 2024 10:28:08 +0000 Subject: [PATCH] add zsh and bash completion scripts --- etc/bash-completion/scrot | 24 ++++++++++++++++++++++++ etc/zsh-completion/_scrot | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 etc/bash-completion/scrot create mode 100644 etc/zsh-completion/_scrot diff --git a/etc/bash-completion/scrot b/etc/bash-completion/scrot new file mode 100644 index 0000000..84dcd49 --- /dev/null +++ b/etc/bash-completion/scrot @@ -0,0 +1,24 @@ +#!/bin/bash + +_scrot_autocomp() { + local -a _scrot_opt_list + IFS=$'\n' _scrot_opt_list=( $(scrot --list-options=tsv) ) 2>/dev/null + local _scrot_opts="" + for ln in "${_scrot_opt_list[@]}"; do + local -a tokens + IFS=$'\t' tokens=( ${ln} ) + + local sopt="${tokens[0]}" + local lopt="${tokens[1]}" + # TODO: better support for flags that accept argument + # local argtype=${tokens[2]%%:*} + # local argdesc=${tokens[2]#*:} + # local desc="[${tokens[3]}]" + _scrot_opts+="--${lopt} " + if [[ "$sopt" = [[:alnum:]]* ]]; then + _scrot_opts+="-${sopt} " + fi + done + printf "%s" "${_scrot_opts% }" +} +complete -W "$(_scrot_autocomp)" scrot diff --git a/etc/zsh-completion/_scrot b/etc/zsh-completion/_scrot new file mode 100644 index 0000000..8919d46 --- /dev/null +++ b/etc/zsh-completion/_scrot @@ -0,0 +1,27 @@ +#compdef _scrot scrot + +function _scrot() { + local -a args + local list=$($~words[1] --list-options=tsv) 2>/dev/null + for ln in ${(f)list}; do + IFS=$'\t' local tokens=( ${=ln} ) + + local sopt="${tokens[1]}" + local lopt="${tokens[2]}" + local argtype=${tokens[3]%%:*} + local argdesc=${tokens[3]#*:} + local desc="[${tokens[4]}]" + + case "$argtype" in + R) desc+=":$argdesc" ;; # Required + O) sopt+="+"; lopt+="=" ;; # Optional + N) ;; # None + esac + + if [[ "${sopt}" = [[:alnum:]]* ]]; then + args+=( "-${sopt}${desc}" ) + fi + args+=( "--${lopt}${desc}" ) + done + _arguments "${args[@]}" +}