Skip to content

Commit

Permalink
add zsh and bash completion scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
N-R-K committed May 28, 2024
1 parent ed51e51 commit 02205eb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
24 changes: 24 additions & 0 deletions etc/bash-completion/scrot
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions etc/zsh-completion/_scrot
Original file line number Diff line number Diff line change
@@ -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[@]}"
}

0 comments on commit 02205eb

Please sign in to comment.