diff --git a/completions/kldload b/completions/kldload index d842b669c4d..4fe8456d7f3 100644 --- a/completions/kldload +++ b/completions/kldload @@ -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 diff --git a/completions/mplayer b/completions/mplayer index dbab3cfcca3..2227ef62626 100644 --- a/completions/mplayer +++ b/completions/mplayer @@ -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) @@ -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) diff --git a/completions/mutt b/completions/mutt index 6e95cc7a6ac..54cb930ebfb 100644 --- a/completions/mutt +++ b/completions/mutt @@ -103,18 +103,16 @@ _comp_cmd_mutt__query() local -a queryresults 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 + if [[ $cur && $querycmd ]]; then local REPLY _comp_expand_tilde "$querycmd" querycmd=$REPLY # $querycmd is expected to be a command with arguments 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