Skip to content

Commit

Permalink
*: various loop iteration improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Apr 26, 2020
1 parent 568c658 commit 911a432
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,7 @@ _known_hosts_real()
fi

# apply suffix and prefix
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
for i in ${!COMPREPLY[*]}; do
COMPREPLY[i]=$prefix$user${COMPREPLY[i]}$suffix
done
fi
Expand Down
4 changes: 2 additions & 2 deletions completions/_umount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ _linux_fstab()
dircur="${cur%/*}/"
fi
basecur=${cur#"$dircur"}
local i n=${#COMPREPLY[@]}
for (( i=0; i < n; i++ )); do
local i
for i in ${!COMPREPLY[*]}; do
[[ "${COMPREPLY[i]}" == "$realcur"* ]] &&
COMPREPLY+=( $(cd "$dircur" 2>/dev/null &&
compgen -f -d -P "$dircur" \
Expand Down
12 changes: 6 additions & 6 deletions completions/dpkg-source
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _dpkg_source()
local cur prev words cword
_init_completion || return

local options work i action packopts unpackopts fields
local options word action packopts unpackopts fields

packopts="-c -l -F -V -T -D -U -W -E -sa -i -I -sk -sr -ss -sA -sK -sP \
-sU -sR"
Expand All @@ -14,13 +14,13 @@ _dpkg_source()
fields="Format Source Version Binary Maintainer Uploader Architecture \
Standards-Version Build-Depends Files"

action="options"
for (( i=1; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == "-x" ]]; then
action=options
for word in "${words[@]:1}"; do
if [[ $word == -x ]]; then
action=unpack
elif [[ ${words[i]} == "-b" ]]; then
elif [[ $word == -b ]]; then
action=pack
elif [[ ${words[i]} == "-h" ]]; then
elif [[ $word == -h ]]; then
action=help
fi
done
Expand Down
2 changes: 1 addition & 1 deletion completions/info
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ _info()
# weed out directory path names and paths to info pages
COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
# weed out info dir file
for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
for i in ${!COMPREPLY[*]}; do
[[ ${COMPREPLY[i]} == dir ]] && unset "COMPREPLY[i]"
done
# strip suffix from info pages
Expand Down
8 changes: 4 additions & 4 deletions completions/pkg-config
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ _pkg_config()
return
;;
--variable)
local i
for (( i=1; i < ${#words[@]}; i++ )); do
if [[ ${words[i]} != -* ]]; then
local word
for word in "${words[@]:1}"; do
if [[ $word != -* ]]; then
COMPREPLY=( $(compgen -W \
'$("$1" ${words[i]} --print-variables 2>/dev/null)' \
'$("$1" $word --print-variables 2>/dev/null)' \
-- "$cur") )
break
fi
Expand Down
4 changes: 2 additions & 2 deletions completions/rcs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ _rcs()

COMPREPLY=( $(compgen -f -- "$dir/RCS/$file") )

for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
for i in ${!COMPREPLY[*]}; do
file=${COMPREPLY[i]##*/}
dir=${COMPREPLY[i]%RCS/*}
COMPREPLY[i]=$dir$file
done

COMPREPLY+=( $(compgen -G "$dir/$file*,v") )

for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
for i in ${!COMPREPLY[*]}; do
COMPREPLY[i]=${COMPREPLY[i]%,v}
done

Expand Down
6 changes: 3 additions & 3 deletions completions/unpack200
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ _unpack200()
$split && return

# Check if a pack or a jar was already given.
local i pack=false jar=false
for (( i=1; i < ${#words[@]}-1; i++ )); do
case ${words[i]} in
local word pack=false jar=false
for word in "${words[@]:1}"; do
case $word in
*.pack|*.pack.gz) pack=true ;;
*.jar) jar=true ;;
esac
Expand Down
8 changes: 4 additions & 4 deletions completions/valgrind
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ _valgrind()
fi
done

local tool
for (( i=1; i < ${#words[@]}; i++ )); do
if [[ ${words[i]} == --tool=?* ]]; then
tool=${words[i]}
local word tool
for word in "${words[@]:1}"; do
if [[ $word == --tool=?* ]]; then
tool=$word
break
fi
done
Expand Down
7 changes: 4 additions & 3 deletions completions/wodim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _cdrecord()
local cur prev words cword
_init_completion -n = || return

local i generic_options track_options track_mode
local generic_options track_options track_mode

# foo=bar style option
if [[ "$cur" == *=* ]]; then
Expand Down Expand Up @@ -71,8 +71,9 @@ _cdrecord()
if [[ -f $prev ]]; then
track_mode=1
else
for (( i=0; i < ${#track_options[@]}; i++ )); do
if [[ "${track_options[i]}" == "$prev" ]]; then
local opt
for opt in "${track_options[@]}"; do
if [[ $opt == "$prev" ]]; then
track_mode=1
break
fi
Expand Down

0 comments on commit 911a432

Please sign in to comment.