Skip to content

fix: fix misc problems before applying _comp_split changes #1084

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 17 commits into from
Jan 3, 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
8 changes: 2 additions & 6 deletions completions/cvs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ _comp_cmd_cvs__entries()

_comp_cmd_cvs__modules()
{
if [[ $prefix ]]; then
COMPREPLY=($(command ls -d "${cvsroot}/${prefix}"/!(CVSROOT)))
else
COMPREPLY=($(command ls -d "${cvsroot}"/!(CVSROOT)))
fi
COMPREPLY=($(command ls -d "${cvsroot}${prefix:+/$prefix}"/!(CVSROOT)))
}

_comp_cmd_cvs__compgen_commands()
Expand Down Expand Up @@ -346,7 +342,7 @@ _comp_cmd_cvs()
local prefix=${cur%/*}
if [[ -r ${cvsroot}/${prefix} ]]; then
_comp_cmd_cvs__modules
COMPREPLY=(${COMPREPLY[@]#$cvsroot})
COMPREPLY=(${COMPREPLY[@]#"$cvsroot"})
COMPREPLY=(${COMPREPLY[@]#\/})
fi
pwd=$(pwd)
Expand Down
4 changes: 2 additions & 2 deletions completions/dot
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ _comp_cmd_dot()
return
;;
-o*)
_comp_compgen -c "${cur#-o}" filedir
((${#COMPREPLY[@]})) && COMPREPLY=("${COMPREPLY[@]/#/-o}")
_comp_compgen -c "${cur#-o}" filedir &&
COMPREPLY=("${COMPREPLY[@]/#/-o}")
return
;;
esac
Expand Down
1 change: 1 addition & 0 deletions completions/dpkg-source
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ _comp_cmd_dpkg_source()
-F)
# -F: force change log format
COMPREPLY=($(command ls /usr/lib/dpkg/parsechangelog))
((${#COMPREPLY[@]})) && _comp_compgen -- -W '"${COMPREPLY[@]}"'
;;
-V)
# -V: set a substitution variable
Expand Down
4 changes: 2 additions & 2 deletions completions/invoke-rc.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ _comp_cmd_invoke_rc_d()
[[ -d /etc/rc.d/init.d ]] && sysvdir=/etc/rc.d/init.d ||
sysvdir=/etc/init.d

services=($sysvdir/!(README*|*.sh|$_comp_backup_glob))
services=(${services[@]#$sysvdir/})
options=(--help --quiet --force --try-anyway --disclose-deny --query
--no-fallback)

Expand All @@ -24,6 +22,8 @@ _comp_cmd_invoke_rc_d()
sort | uniq -u
))
((${#valid_options[@]})) && COMPREPLY+=("${valid_options[@]}")
services=($sysvdir/!(README*|*.sh|$_comp_backup_glob))
services=(${services[@]#$sysvdir/})
((${#services[@]})) && COMPREPLY+=("${services[@]}")
((${#COMPREPLY[@]})) &&
_comp_compgen -- -W '"${COMPREPLY[@]}"'
Expand Down
2 changes: 1 addition & 1 deletion completions/java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _comp_cmd_java__classes()
local -a classpaths=("${REPLY[@]}")

# convert package syntax to path syntax
cur=${cur//.//}
local cur=${cur//.//}
# parse each classpath element for classes
for i in "${classpaths[@]}"; do
if [[ $i == *.@(jar|zip) && -r $i ]]; then
Expand Down
16 changes: 9 additions & 7 deletions completions/kldload
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ _comp_cmd_kldload()
moddirs=($(kldconfig -r 2>/dev/null))
_comp_unlocal IFS

compopt -o filenames
for i in "${moddirs[@]}"; do
_comp_compgen -v modules -c "$i/$cur" -- -f &&
COMPREPLY+=("${modules[@]#$i/}")
done
((${#COMPREPLY[@]})) &&
COMPREPLY=("${COMPREPLY[@]%.ko}")
if ((${#moddirs[@]})); then
compopt -o filenames
for i in "${moddirs[@]}"; do
_comp_compgen -v modules -c "$i/$cur" -- -f &&
COMPREPLY+=("${modules[@]#$i/}")
done
((${#COMPREPLY[@]})) &&
COMPREPLY=("${COMPREPLY[@]%.ko}")
fi

# also add dirs in current dir
_comp_compgen -a filedir -d
Expand Down
39 changes: 21 additions & 18 deletions completions/mplayer
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ _comp_cmd_mplayer()
return
;;
-vobsub)
_comp_compgen_filedir '@(idx|ifo|sub)'
local IFS=$'\n'
COMPREPLY=($(for i in "${COMPREPLY[@]}"; do
if [[ -f $i && -r $i ]]; then
printf '%s\n' "${i%.*}"
else
printf '%s\n' "$i"
fi
done))
if _comp_compgen_filedir '@(idx|ifo|sub)'; then
local IFS=$'\n'
COMPREPLY=($(for i in "${COMPREPLY[@]}"; do
if [[ -f $i && -r $i ]]; then
printf '%s\n' "${i%.*}"
else
printf '%s\n' "$i"
fi
done))
fi
return
;;
-subcp | -msgcharset)
Expand Down Expand Up @@ -84,15 +85,17 @@ _comp_cmd_mplayer()
dirs=(/usr/share/mplayer/skins /usr/local/share/mplayer/skins)
fi

local -a subdirs
for i in ~/.mplayer/skins "${dirs[@]}"; do
if [[ -d $i && -r $i ]]; then
_comp_compgen -v subdirs -c "$i/$cur" -- -d
for j in "${subdirs[@]}"; do
COMPREPLY[k++]=${j#"$i/"}
done
fi
done
if ((${#dirs[@]})); then
local -a subdirs
for i in ~/.mplayer/skins "${dirs[@]}"; do
if [[ -d $i && -r $i ]]; then
_comp_compgen -v subdirs -c "$i/$cur" -- -d
for j in "${subdirs[@]}"; do
COMPREPLY[k++]=${j#"$i/"}
done
fi
done
fi
return
;;
-cdrom-device)
Expand Down
19 changes: 9 additions & 10 deletions completions/mutt
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,21 @@ _comp_cmd_mutt__aliases()
# @param $1 (cur) Current word to complete
_comp_cmd_mutt__query()
{
local cur=$1 querycmd muttcmd=${words[0]}
local -a queryresults
local cur=$1
[[ $cur ]] || return 0
local muttcmd=${words[0]}

querycmd="$("$muttcmd" -Q query_command 2>/dev/null | command sed -e 's|^query_command=\"\(.*\)\"$|\1|' -e 's|%s|'"$cur"'|')"
if [[ ! $cur || ! $querycmd ]]; then
queryresults=()
else
local querycmd="$("$muttcmd" -Q query_command 2>/dev/null | command sed -e 's|^query_command=\"\(.*\)\"$|\1|' -e 's|%s|'"$cur"'|')"
if [[ $querycmd ]]; then
local REPLY
_comp_expand_tilde "$querycmd"
querycmd=$REPLY
# $querycmd is expected to be a command with arguments
queryresults=($($querycmd |
local -a queryresults=($($querycmd |
command sed -n '2,$s|^\([^[:space:]]\{1,\}\).*|\1|p'))
((${#queryresults[@]})) &&
_comp_compgen -a -- -W '"${queryresults[@]}"'
fi

_comp_compgen -a -- -W "${queryresults[*]}"
}

# @param $1 (cur) Current word to complete
Expand All @@ -131,7 +130,7 @@ _comp_cmd_mutt__filedir()
# (minus the leading '=' sign).
compopt -o filenames
_comp_compgen -c "$folder/${cur:1}" -- -f
COMPREPLY=(${COMPREPLY[@]#$folder/})
COMPREPLY=(${COMPREPLY[@]#"$folder/"})
return
elif [[ $cur == !* ]]; then
spoolfile="$("$muttcmd" -F "$muttrc" -Q spoolfile 2>/dev/null |
Expand Down
2 changes: 1 addition & 1 deletion completions/pkg_delete
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_pkg_delete()
[[ $prev == -o || $prev == -p || $prev == -W ]] && return

_comp_compgen -c "$pkgdir$cur" -- -d
((${#COMPREPLY[@]} == 0)) || COMPREPLY=(${COMPREPLY[@]#$pkgdir})
((${#COMPREPLY[@]} == 0)) || COMPREPLY=(${COMPREPLY[@]#"$pkgdir"})

} &&
complete -F _comp_cmd_pkg_delete -o dirnames \
Expand Down
4 changes: 2 additions & 2 deletions completions/pkgutil
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ _comp_cmd_pkgutil()
_comp_initialize -n : -- "$@" || return

local command="" catalog_files configuration_files
declare -a configuration_files=(
local -a configuration_files=(
"/opt/csw/etc/pkgutil.conf" "/etc/opt/csw/pkgutil.conf")
declare -a catalog_files=()
local -a catalog_files=()

local i=$cword REPLY
while ((i-- > 1)); do
Expand Down
2 changes: 1 addition & 1 deletion completions/portupgrade
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_portupgrade()
local pkgdir=${PKG_DBDIR:-/var/db/pkg}/

_comp_compgen -c "$pkgdir$cur" -- -d
COMPREPLY=(${COMPREPLY[@]#$pkgdir})
COMPREPLY=(${COMPREPLY[@]#"$pkgdir"})
COMPREPLY=(${COMPREPLY[@]%-*})

} &&
Expand Down
5 changes: 2 additions & 3 deletions completions/povray
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ _comp_cmd_povray()
[-+]I*)
cur="${povcur#[-+]I}" # to confuse _comp_compgen_filedir
pfx="${povcur%"$cur"}"
_comp_compgen_filedir pov
((${#COMPREPLY[@]})) &&
_comp_compgen_filedir pov &&
_comp_compgen -Rv COMPREPLY -- -P "$pfx" -W '"${COMPREPLY[@]}"'
return
;;
Expand All @@ -43,7 +42,7 @@ _comp_cmd_povray()
done
cur="${povcur#[-+]O}" # to confuse _comp_compgen_filedir
pfx="${povcur%"$cur"}"
_comp_compgen -a filedir $oext
_comp_compgen -a filedir "$oext"
((${#COMPREPLY[@]})) &&
_comp_compgen -Rv COMPREPLY -- -P "$pfx" -W '"${COMPREPLY[@]}"'
return
Expand Down
2 changes: 1 addition & 1 deletion completions/reportbug
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _comp_cmd_reportbug()
;;
--from-buildd)
_comp_compgen_split -S "_" -- "$(apt-cache dumpavail |
command grep "^Source: $cur" | sort -u | cut -f2 -d' ')"
_comp_awk -F ' ' '$1 == "Source:" && !uniq[$2]++ { print $2 }')"
return
;;
--smtphost)
Expand Down
19 changes: 10 additions & 9 deletions completions/svcadm
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ _comp_cmd_svcadm__fmri()
# we generate all possibles abbreviations for the FMRI
# no need to have a generic loop as we will have a finite
# number of components
local IFS="/"
set -- "$fmri"
_comp_unlocal IFS
case $# in
1) fmri_part_list=" $1" ;;
2) fmri_part_list=" $2 $1/$2" ;;
3) fmri_part_list=" $3 $2/$3 $1/$2/$3" ;;
4) fmri_part_list=" $4 $3/$4 $2/$3/$4 $1/$2/$3/$4" ;;
esac
local -a tmp
if _comp_split -F / tmp "$fmri"; then
set -- "${tmp[@]}"
case $# in
1) fmri_part_list=" $1" ;;
2) fmri_part_list=" $2 $1/$2" ;;
3) fmri_part_list=" $3 $2/$3 $1/$2/$3" ;;
4) fmri_part_list=" $4 $3/$4 $2/$3/$4 $1/$2/$3/$4" ;;
esac
fi
else
fmri_part_list="$fmri"
fi
Expand Down
4 changes: 2 additions & 2 deletions completions/tipc
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ _comp_cmd_tipc()
done
case "$media" in
"udp")
declare -a params=("localip" "localport" "remoteip"
local -a params=("localip" "localport" "remoteip"
"remoteport" "domain" "priority")
;;
"eth" | "ib")
declare -a params=("domain" "priority")
local -a params=("domain" "priority")
;;
*)
return
Expand Down
15 changes: 8 additions & 7 deletions completions/vncviewer
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,14 @@ _comp_cmd_xvnc4viewer()
WMDecorationWidth ZlibLevel)
[[ $cur == --* ]] && dash=-- || dash=-

local IFS=$' \t\n' reset=$(shopt -p nocasematch)
shopt -s nocasematch
local option
COMPREPLY=($(for option in "${options[@]}"; do
[[ $dash$option == "$cur"* ]] && printf '%s\n' "$dash$option"
done))
$reset
local IFS=$' \t\n'
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
1 change: 1 addition & 0 deletions completions/wol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ _comp_cmd_wol()
-ne 's/.*[[:space:]]Bcast:\([^[:space:]]*\).*/\1/p' \
-ne 's/.*inet.*[[:space:]]brd[[:space:]]\([^[:space:]]*\).*/\1/p' \
-ne 's/.*[[:space:]]broadcast[[:space:]]\{1,\}\([^[:space:]]*\).*/\1/p'))
((${#COMPREPLY[@]})) && _comp_compgen -- -W '"${COMPREPLY[@]}"'
_comp_compgen -a known_hosts -- "$cur"
return
;;
Expand Down