mirror of
https://github.com/albfan/miraclecast.git
synced 2025-03-09 23:38:56 +00:00
bash completion with lazy load
This commit is contained in:
parent
5bfc97a72c
commit
ec7e11c8bf
7 changed files with 192 additions and 45 deletions
85
res/miracle-wifictl
Executable file
85
res/miracle-wifictl
Executable file
|
@ -0,0 +1,85 @@
|
|||
#
|
||||
# Autocompletion for miracle-wifictl
|
||||
#
|
||||
# Maintainer: Alberto Fanjul <albertofanjul@gmail.com>
|
||||
#
|
||||
|
||||
function _miracle-wifictl() {
|
||||
local cur prev
|
||||
|
||||
_get_comp_words_by_ref cur
|
||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
|
||||
case "$prev" in
|
||||
--log-level)
|
||||
COMPREPLY=($(compgen -W 'fatal alert critical error warning notice info debug trace 1 2 3 4 5 6 7 8' -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=($(compgen -W "$(_parse_help miracle-wifictl) $(_parse_short_help miracle-wifictl)" -- "$cur"))
|
||||
}
|
||||
|
||||
_parse_short_help ()
|
||||
{
|
||||
eval local cmd=$( quote "$1" );
|
||||
local line;
|
||||
{
|
||||
case $cmd in
|
||||
-)
|
||||
cat
|
||||
;;
|
||||
*)
|
||||
LC_ALL=C "$( dequote "$cmd" )" ${2:---help} 2>&1
|
||||
;;
|
||||
esac
|
||||
} | while read -r line; do
|
||||
[[ $line == *([[:blank:]])-* ]] || continue;
|
||||
while [[ $line =~ ((^|[^-])-[A-Za-z0-9?][[:space:]]+)\[?[A-Z0-9]+\]? ]]; do
|
||||
line=${line/"${BASH_REMATCH[0]}"/"${BASH_REMATCH[1]}"};
|
||||
done;
|
||||
__parse_short_options "${line// or /, }";
|
||||
done
|
||||
}
|
||||
|
||||
__parse_short_options ()
|
||||
{
|
||||
local option option2 i IFS='
|
||||
,/|';
|
||||
option=;
|
||||
local -a array;
|
||||
read -a array <<< "$1";
|
||||
for i in "${array[@]}";
|
||||
do
|
||||
case "$i" in
|
||||
---*)
|
||||
break
|
||||
;;
|
||||
--?*)
|
||||
break
|
||||
;;
|
||||
-?*)
|
||||
option=$i;
|
||||
break
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac;
|
||||
done;
|
||||
[[ -n $option ]] || return;
|
||||
IFS='
|
||||
';
|
||||
if [[ $option =~ (\[((no|dont)-?)\]). ]]; then
|
||||
option2=${option/"${BASH_REMATCH[1]}"/};
|
||||
option2=${option2%%[<{().[]*};
|
||||
printf '%s\n' "${option2/=*/=}";
|
||||
option=${option/"${BASH_REMATCH[1]}"/"${BASH_REMATCH[2]}"};
|
||||
fi;
|
||||
option=${option%%[<{().[]*};
|
||||
printf '%s\n' "${option/=*/=}"
|
||||
}
|
||||
|
||||
complete -F _miracle-wifictl miracle-wifictl
|
||||
|
||||
# ex: filetype=sh
|
Loading…
Add table
Add a link
Reference in a new issue