Skip to content

Commit 2b52cad

Browse files
committed
Avoid pollution with global variables in info commands
1 parent 1daa08b commit 2b52cad

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

command/info.sh

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,58 +24,60 @@ typeset -A _Dbg_command_help_info
2424
_Dbg_help_add info '' 1 _Dbg_complete_info
2525

2626
# Load in "info" subcommands
27-
for _Dbg_file in "${_Dbg_libdir}/command/info_sub/"*.sh ; do
28-
source "$_Dbg_file"
27+
for _Dbg_file in "${_Dbg_libdir}/command/info_sub/"*.sh; do
28+
source "$_Dbg_file"
2929
done
3030

3131
# Command completion
3232
_Dbg_complete_info() {
33-
_Dbg_complete_subcmd info
33+
_Dbg_complete_subcmd info
3434
}
3535

3636
_Dbg_do_info() {
37+
if (($# > 0)); then
38+
typeset _Dbg_subcmd="$1"
39+
shift
3740

38-
if (($# > 0)) ; then
39-
typeset subcmd=$1
40-
shift
41+
if [[ -n ${_Dbg_debugger_info_commands["$_Dbg_subcmd"]} ]]; then
42+
${_Dbg_debugger_info_commands["$_Dbg_subcmd"]} "$@"
43+
return $?
44+
else
45+
# Look for a unique abbreviation
46+
typeset -i _Dbg_found=0
47+
typeset -i _Dbg_count=0
48+
typeset _Dbg_list
49+
_Dbg_list="${!_Dbg_debugger_info_commands[@]}"
50+
for _Dbg_try in $_Dbg_list; do
51+
if [[ $_Dbg_try =~ ^$_Dbg_subcmd ]]; then
52+
_Dbg_subcmd="$_Dbg_try"
53+
((_Dbg_count++))
54+
fi
55+
done
56+
((_Dbg_found = (_Dbg_count == 1)))
57+
fi
58+
if ((_Dbg_found)); then
59+
${_Dbg_debugger_info_commands["$_Dbg_subcmd"]} "$@"
60+
return $?
61+
fi
4162

42-
typeset -i found=0
43-
44-
if [[ -n ${_Dbg_debugger_info_commands[$subcmd]} ]] ; then
45-
${_Dbg_debugger_info_commands[$subcmd]} "$@"
46-
return $?
47-
else
48-
# Look for a unique abbreviation
49-
typeset -i count=0
50-
typeset list; list="${!_Dbg_debugger_info_commands[@]}"
51-
for try in $list ; do
52-
if [[ $try =~ ^$subcmd ]] ; then
53-
subcmd=$try
54-
((count++))
55-
fi
56-
done
57-
((found=(count==1)))
58-
fi
59-
if ((found)); then
60-
${_Dbg_debugger_info_commands[$subcmd]} "$@"
61-
return $?
62-
fi
63-
64-
_Dbg_errmsg "Unknown info subcommand: $subcmd"
65-
msg=_Dbg_errmsg
63+
_Dbg_errmsg "Unknown info subcommand: $_Dbg_subcmd"
64+
_Dbg_msg=_Dbg_errmsg
6665
else
67-
msg=_Dbg_msg
66+
_Dbg_msg=_Dbg_msg
6867
fi
69-
typeset -a list
70-
list=(${!_Dbg_debugger_info_commands[@]})
71-
sort_list 0 ${#list[@]}-1
72-
typeset columnized=''
73-
typeset -i width; ((width=_Dbg_set_linewidth-5))
74-
typeset -a columnized; columnize $width
75-
typeset -i i
76-
$msg "Info subcommands are:"
77-
for ((i=0; i<${#columnized[@]}; i++)) ; do
78-
$msg " ${columnized[i]}"
68+
69+
typeset -a _Dbg_list
70+
_Dbg_list=(${!_Dbg_debugger_info_commands[@]})
71+
sort_list 0 ${#_Dbg_list[@]}-1
72+
typeset _Dbg_columnized=''
73+
typeset -i _Dbg_width
74+
((_Dbg_width = _Dbg_set_linewidth - 5))
75+
typeset -a _Dbg_columnized
76+
columnize $_Dbg_width
77+
typeset -i _Dbg_i
78+
$_Dbg_msg "Info subcommands are:"
79+
for ((_Dbg_i = 0; _Dbg_i < ${#_Dbg_columnized[@]}; _Dbg_i++)); do
80+
$_Dbg_msg " ${_Dbg_columnized[_Dbg_i]}"
7981
done
8082
return 1
8183
}

0 commit comments

Comments
 (0)