Skip to content

Commit

Permalink
refactor(mcrypt,postcat,svcadm,tar,wodim): switch to boolean variables
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Apr 5, 2023
1 parent 2bad01c commit 71ed5f1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
6 changes: 3 additions & 3 deletions completions/mcrypt
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ _mcrypt()
elif [[ ${words[0]} == mdecrypt ]]; then
_filedir nc
else
local i decrypt=0
local i decrypt=false
for ((i = 1; i < ${#words[@]} - 1; i++)); do
if [[ ${words[i]} == -@(d|-decrypt) ]]; then
_filedir nc
decrypt=1
decrypt=true
break
fi
done
if ((decrypt == 0)); then
if ! "$decrypt"; then
_filedir
fi
fi
Expand Down
6 changes: 3 additions & 3 deletions completions/postcat
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ _postcat()
return
fi

local idx qfile=0
local idx qfile=false
for idx in "${words[@]}"; do
[[ $idx == -q ]] && qfile=1 && break
[[ $idx == -q ]] && qfile=true && break
done
if ((qfile == 1)); then
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
Expand Down
6 changes: 3 additions & 3 deletions completions/svcadm
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ _smf_complete_fmri()
{
local cur="$1" prefix="$2"
local cur_prefix fmri fmri_list=""
local exact_mode="" pattern
local exact_mode=false pattern

if [[ $cur == $prefix* ]]; then
[[ $cur == "$prefix" ]] && cur+="/"
pattern="$cur*"
exact_mode=1
exact_mode=true
else
pattern="$prefix*/$cur*"
fi
Expand All @@ -38,7 +38,7 @@ _smf_complete_fmri()

for fmri in $(svcs -H -o FMRI "$pattern" 2>/dev/null); do
local fmri_part_list fmri_part
if [[ ! $exact_mode ]]; then
if ! "$exact_mode"; then
fmri=${fmri#"$prefix/"}

# we generate all possibles abbreviations for the FMRI
Expand Down
25 changes: 12 additions & 13 deletions completions/tar
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ __tar_parse_old_opt()

# current word is the first word
[[ $cword -eq 1 && $cur && ${cur:0:1} != '-' ]] &&
old_opt_progress=1
old_opt_progress=true

# check that first argument does not begin with "-"
first_word=${words[1]}
[[ $first_word && ${first_word:0:1} != "-" ]] &&
old_opt_used=1
old_opt_used=true

# parse the old option (if present) contents to allow later code expect
# corresponding arguments
if ((old_opt_used == 1)); then
if "$old_opt_used"; then
char=${first_word:0:1}
while [[ $char ]]; do
if __tar_is_argreq "$char"; then
Expand All @@ -195,13 +195,12 @@ __tar_parse_old_opt()
# Make the analysis of whole command line.
__tar_preparse_cmdline()
{
local first_arg i modes="ctxurdA"
local first_arg=true i modes="ctxurdA"

shift # progname

__tar_parse_old_opt

first_arg=1
for i in "$@"; do
case "$i" in
--delete | --test-label)
Expand All @@ -220,14 +219,14 @@ __tar_preparse_cmdline()
;;
*[$modes]*)
# Only the first arg may be "MODE" without leading dash
if ((first_arg == 1)); then
if "$first_arg"; then
tar_mode=${i//[^$modes]/}
tar_mode=${tar_mode:0:1}
tar_mode_arg=$i
fi
;;
esac
first_arg=0
first_arg=false
done
}

Expand Down Expand Up @@ -306,7 +305,7 @@ __tar_complete_mode()

# The last short option requires argument, like '-cf<TAB>'. Cut the
# completion here to enforce argument processing.
if ((old_opt_progress == 0)) &&
if ! "$old_opt_progress" &&
__tar_is_argreq "$(__tar_last_char "$cur")"; then
COMPREPLY=("$cur") && return 0
fi
Expand Down Expand Up @@ -383,7 +382,7 @@ __tar_adjust_PREV_from_old_option()
# deal with old style arguments here
# $ tar cfTC # expects this sequence of arguments:
# $ tar cfTC ARCHIVE_FILE PATTERNS_FILE CHANGE_DIR
if ((old_opt_used == 1 && cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then
if "$old_opt_used" && ((cword > 1 && cword < ${#old_opt_parsed[@]} + 2)); then
# make e.g. 'C' option from 'cffCT'
prev="-${old_opt_parsed[cword - 2]}"
fi
Expand Down Expand Up @@ -488,8 +487,8 @@ _gtar()
local long_opts short_opts basic_tar=false \
long_arg_none="" long_arg_opt="" long_arg_req="" \
short_arg_none="" short_arg_opt="" short_arg_req="" \
tar_mode tar_mode_arg old_opt_progress=0 \
old_opt_used=0 old_opt_parsed=()
tar_mode tar_mode_arg old_opt_progress=false \
old_opt_used=false old_opt_parsed=()

# Main mode, e.g. -x or -c (extract/creation)
local tar_mode=none
Expand Down Expand Up @@ -678,8 +677,8 @@ _posix_tar()
local long_opts short_opts basic_tar=true \
long_arg_none="" long_arg_opt long_arg_req="" \
short_arg_none short_arg_opt short_arg_req \
tar_mode tar_mode_arg old_opt_progress=0 \
old_opt_used=1 old_opt_parsed=()
tar_mode tar_mode_arg old_opt_progress=false \
old_opt_used=true old_opt_parsed=()

# Main mode, e.g. -x or -c (extract/creation)
local tar_mode=none
Expand Down
8 changes: 4 additions & 4 deletions completions/wodim
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ _cdrecord()
-isosize -pad -nopad -shorttrack -noshorttrack -preemp -nopreemp
-copy -nocopy -scms "isrc=" "index=" "padsize=" "pregap=" "tsize=")
# look if previous was either a file or a track option
track_mode=0
track_mode=false
if ((cword > 1)); then
if [[ -f $prev ]]; then
track_mode=1
track_mode=true
else
local opt
for opt in "${track_options[@]}"; do
if [[ $opt == "$prev" ]]; then
track_mode=1
track_mode=true
break
fi
done
Expand All @@ -86,7 +86,7 @@ _cdrecord()
# track options are always available
COMPREPLY+=($(compgen -W '"${track_options[@]}"' -- "$cur"))
# general options are no more available after file or track option
if ((track_mode == 0)); then
if ! "$track_mode"; then
COMPREPLY+=($(compgen -W '"${generic_options[@]}"' -- "$cur"))
fi
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
Expand Down

0 comments on commit 71ed5f1

Please sign in to comment.