Skip to content

fix: refactor array assignments with manual cur filtering #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions completions/_slackpkg
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ _comp_cmd_slackpkg()
_comp_compgen_filedir
_comp_compgen -a -- -W 'a ap d e f k kde kdei l n t tcl x xap xfce
y'
COMPREPLY+=($(cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null |
command grep "^$cur"))
_comp_compgen -a split -l -- "$(
cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null
)"
return
;;
info)
COMPREPLY=($(cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null |
command grep "^$cur"))
_comp_compgen_split "$(
cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null
)"
return
;;
update)
Expand Down
8 changes: 4 additions & 4 deletions completions/_yum
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ _comp_cmd_yum__list()
if [[ $1 == all ]]; then
# Try to strip in between headings like "Available Packages"
# This will obviously only work for English :P
COMPREPLY=($(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
_comp_split COMPREPLY "$(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
command sed -ne '/^Available /d' -e '/^Installed /d' \
-e '/^Updated /d' -e 's/[[:space:]].*//p'))
-e '/^Updated /d' -e 's/[[:space:]].*//p')"
else
# Drop first line (e.g. "Updated Packages")
COMPREPLY=($(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
command sed -ne 1d -e 's/[[:space:]].*//p'))
_comp_split COMPREPLY "$(yum -d 0 -C list "$1" "$cur*" 2>/dev/null |
command sed -ne 1d -e 's/[[:space:]].*//p')"
fi
}

Expand Down
5 changes: 2 additions & 3 deletions completions/aptitude
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ _comp_cmd_aptitude()
return
;;
--target-release | --default-release | -${noargopts}t)
COMPREPLY=($(apt-cache policy |
command grep "release.o=Debian,a=$cur" |
command sed -e "s/.*a=\([_[:alnum:]]*\).*/\1/" | uniq 2>/dev/null))
_comp_compgen_split -l -- "$(apt-cache policy |
command sed -ne 's/.*release.o=Debian,a=\([_[:alnum:]]*\).*/\1/p')"
return
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions completions/cpan2dist
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ _comp_cmd_cpan2dist()
[[ -d $dir && -r "$dir/02packages.details.txt.gz" ]] &&
packagelist="$dir/02packages.details.txt.gz"
done
[[ $packagelist ]] && COMPREPLY=($(zgrep "^${cur//-/::}" \
[[ $packagelist ]] && _comp_split COMPREPLY "$(zgrep "^${cur//-/::}" \
"$packagelist" 2>/dev/null | _comp_awk '{print $1}' |
command sed -e 's/::/-/g'))
command sed -e 's/::/-/g')"
fi
} &&
complete -F _comp_cmd_cpan2dist -o default cpan2dist
Expand Down
4 changes: 3 additions & 1 deletion completions/isql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ _comp_cmd_isql()
_comp_initialize -- "$@" || return

[[ -f ${ODBCINI-} ]] &&
COMPREPLY=($(command grep "\[$cur" "$ODBCINI" | tr -d \[\]))
_comp_compgen_split -l -- "$(
command sed -n 's/\]//g;s/^\[//gp' "$ODBCINI"
)"
} &&
complete -F _comp_cmd_isql isql

Expand Down
5 changes: 2 additions & 3 deletions completions/make
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ _comp_cmd_make()
# mode=-d # display-only mode
# fi

local IFS=$' \t\n'
COMPREPLY=($(LC_ALL=C \
_comp_split COMPREPLY "$(LC_ALL=C \
$1 -npq __BASH_MAKE_COMPLETION__=1 \
${makef+"${makef[@]}"} "${makef_dir[@]}" .DEFAULT 2>/dev/null |
_comp_cmd_make__extract_targets "$mode" "$cur"))
_comp_cmd_make__extract_targets "$mode" "$cur")"

_comp_cmd_make__truncate_non_unique_paths

Expand Down
9 changes: 2 additions & 7 deletions completions/postcat
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,8 @@ _comp_cmd_postcat()
[[ $idx == -q ]] && qfile=set && break
done
if [[ $qfile ]]; then
local len=${#cur} pval
for pval in $(mailq 2>/dev/null |
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do
if [[ $cur == "${pval:0:len}" ]]; then
COMPREPLY+=("$pval")
fi
done
_comp_compgen_split -- "$(mailq 2>/dev/null |
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//')"
return
fi

Expand Down
29 changes: 6 additions & 23 deletions completions/postsuper
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,25 @@ _comp_cmd_postsuper()
local cur prev words cword comp_args
_comp_initialize -- "$@" || return

local pval len

case $prev in
-c)
_comp_compgen_filedir -d
return
;;
-[dr])
len=${#cur}
for pval in ALL $(mailq 2>/dev/null |
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//'); do
if [[ $cur == "${pval:0:len}" ]]; then
COMPREPLY+=($pval)
fi
done
_comp_compgen_split -- "ALL $(mailq 2>/dev/null |
command sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//')"
return
;;
-h)
len=${#cur}
for pval in ALL $(mailq 2>/dev/null |
_comp_compgen_split -- "ALL $(mailq 2>/dev/null |
command sed \
-e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* ].*$//; /!$/d'); do
if [[ $cur == "${pval:0:len}" ]]; then
COMPREPLY+=($pval)
fi
done
-e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* ].*$//; /!$/d')"
return
;;
-H)
len=${#cur}
for pval in ALL $(mailq 2>/dev/null | command sed -e \
'1d; $d; /^[^0-9A-Z]/d; /^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//'); do
if [[ $cur == "${pval:0:len}" ]]; then
COMPREPLY+=($pval)
fi
done
_comp_compgen_split -- "ALL $(mailq 2>/dev/null | command sed \
-e '1d; $d; /^[^0-9A-Z]/d; /^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//')"
return
;;
esac
Expand Down
7 changes: 3 additions & 4 deletions completions/povray
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ _comp_cmd_povray()
cur="${povcur#*\[}"
pfx="${povcur%\["$cur"}" # prefix == filename
[[ -f $pfx && -r $pfx ]] || return
COMPREPLY=($(command sed -ne \
's/^[[:space:]]*\[\('"$cur"'[^]]*\]\).*$/\1/p' -- "$pfx"))
# to prevent [bar] expand to nothing. can be done more easily?
((${#COMPREPLY[@]})) &&
_comp_compgen_split -l -- "$(command sed -ne \
's/^[[:space:]]*\[\([^]]*\]\).*$/\1/p' -- "$pfx")" &&
# to prevent [bar] expand to nothing. can be done more easily?
_comp_compgen -Rv COMPREPLY -- -P "${pfx}[" -W '"${COMPREPLY[@]}"'
return
;;
Expand Down
6 changes: 2 additions & 4 deletions completions/sbopkg
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ _comp_cmd_sbopkg()
local file=${REPO_ROOT-}/${REPO_NAME-}/${REPO_BRANCH-}/SLACKBUILDS.TXT
[[ -f $file && -r $file ]] || return

COMPREPLY=($(
command sed -ne "/^SLACKBUILD NAME: $cur/{s/^SLACKBUILD NAME: //;p;}" \
"$file"
))
_comp_compgen_split -l -- "$(command sed -ne "s/^SLACKBUILD NAME: //p" \
"$file")"
_comp_compgen -aC "$QUEUEDIR" -- -f -X "!*.sqf"
} &&
complete -F _comp_cmd_sbopkg sbopkg
Expand Down
12 changes: 8 additions & 4 deletions completions/slapt-get
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ _comp_cmd_slapt_get()
# slapt-get will fail to search for "^name-version"
# it can search for names only
local name=${cur%%-*}
COMPREPLY=($(LC_ALL=C "$1" -c "$config" --search "^$name" \
2>/dev/null | LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"))
_comp_compgen_split -l -- "$(
LC_ALL=C "$1" -c "$config" --search "^$name" 2>/dev/null |
LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"
)"
return
;;
avl) # --install|-i|
COMPREPLY=($(LC_ALL=C "$1" -c "$config" --available \
2>/dev/null | LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"))
_comp_compgen_split -l -- "$(
LC_ALL=C "$1" -c "$config" --available 2>/dev/null |
LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"
)"
return
;;
ins) # --remove|--filelist
Expand Down
15 changes: 10 additions & 5 deletions completions/slapt-src
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ _comp_cmd_slapt_src()

if [[ $cur == *:* ]]; then
local name=${cur%:*}
COMPREPLY=($(LC_ALL=C "$1" --config "$config" --search "^$name" \
2>/dev/null | LC_ALL=C command sed -ne \
"/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p;}"))
_comp_compgen_split -l -- "$(
LC_ALL=C
"$1" --config "$config" --search "^$name" 2>/dev/null |
command sed -ne "/^$cur/{s/^$name:\([^ ]*\) .*$/\1/;p;}"
)"
else
COMPREPLY=($(LC_ALL=C "$1" --config "$config" --search "^$cur" \
2>/dev/null | LC_ALL=C command sed -ne "/^$cur/{s/ .*$//;p;}"))
_comp_compgen_split -l -- "$(
LC_ALL=C
"$1" --config "$config" --search "^$cur" 2>/dev/null |
command sed -ne "/^$cur/{s/ .*$//;p;}"
)"
fi
} &&
complete -F _comp_cmd_slapt_src slapt-src
Expand Down
5 changes: 2 additions & 3 deletions completions/vncviewer
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ _comp_cmd_xvnc4viewer()
WMDecorationWidth ZlibLevel)
[[ $cur == --* ]] && dash=-- || dash=-

local IFS=$' \t\n'
COMPREPLY=($(
_comp_split COMPREPLY "$(
shopt -s nocasematch
local option
for option in "${options[@]}"; do
[[ $dash$option == "$cur"* ]] && printf '%s\n' "$dash$option"
done
))
)"
else
_comp_compgen_known_hosts -- "$cur"
fi
Expand Down
6 changes: 2 additions & 4 deletions completions/wvdial
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ _comp_cmd_wvdial()
done
# parse config files for sections and
# remove default section
COMPREPLY=($(
command sed -ne "s|^\[Dialer \($cur.*\)\]$|\1|p" "$config" \
2>/dev/null | command grep -v '^Defaults$'
))
_comp_compgen_split -l -X 'Defaults' -- "$(command sed -ne \
's/^\[Dialer \(.*\)\]$/\1/p' "$config" 2>/dev/null)"
# escape spaces
COMPREPLY=("${COMPREPLY[@]// /\\ }")
;;
Expand Down