Menu

[69de4e]: / command / help.sh  Maximize  Restore  History

Download this file

144 lines (131 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -*- shell-script -*-
# help.sh - gdb-like "help" debugger command
#
# Copyright (C) 2002-2006, 2008, 2010-2011, 2015
# Rocky Bernstein <rocky@gnu.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
# MA 02111 USA.
if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
dirname=${BASH_SOURCE[0]%/*}
[[ $dirname == $0 ]] && top_dir='..' || top_dir=${dirname}/..
for file in help alias ; do source "$top_dir/lib/${file}.sh"; done
fi
_Dbg_help_add help \
'**help** [*command* [*subcommand* ..]]
If no arguments are given, print a list of command names.
With a command name give help for that command. For many commands
you can get further detailed help by listing the subcommand name.
Examples:
---------
help
help up
help set
help set args' 1 _Dbg_complete_help
_Dbg_complete_help() {
typeset -a words;
IFS=' ' words=( $COMP_LINE )
typeset subcmds
subcmds="${!_Dbg_command_help[@]}"
if (( ${#words[@]} == 1 )); then
COMPREPLY=( $subcmds )
elif (( ${#words[@]} == 2 )) ; then
typeset commands="${!_Dbg_command_help[@]}"
COMPREPLY=( $(compgen -W "$subcmds" "${words[1]}") )
else
COMPREPLY=()
fi
}
# print help command
function _Dbg_do_help {
# We have to use be careful to make sure globbing, e.g. * isn't
# done.
# Treat "help *" the same as help
[[ "$_Dbg_args" == '*' ]] && _Dbg_args=''
if [[ '' == $_Dbg_args ]] ; then
_Dbg_help_sort_command_names
_Dbg_section 'Available commands:'
typeset -a list=("${_Dbg_sorted_command_names[@]}")
_Dbg_list_columns
_Dbg_msg ''
_Dbg_msg 'Readline command line editing (emacs/vi mode) is available.'
_Dbg_msg 'Type "help" followed by command name for full documentation.'
return 0
else
typeset dbg_cmd="$1"
if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
_Dbg_msg_rst "${_Dbg_command_help[$dbg_cmd]}"
else
_Dbg_alias_expand $dbg_cmd
dbg_cmd="$expanded_alias"
if [[ -n ${_Dbg_command_help[$dbg_cmd]} ]] ; then
_Dbg_msg_rst "${_Dbg_command_help[$dbg_cmd]}"
else
case $dbg_cmd in
i | in | inf | info )
_Dbg_info_help $2
return
;;
sh | sho | show )
_Dbg_help_show $2
;;
se | set )
_Dbg_help_set $2
;;
* )
# Look for a unique abbreviation
typeset -i count=0
typeset found_cmd
typeset list; list="${!_Dbg_command_help[@]}"
for try in $list ; do
if [[ $try =~ ^$dbg_cmd ]] ; then
found_cmd=$try
((count++))
fi
done
((found=(count==1)))
if ((found)); then
_Dbg_msg "${_Dbg_command_help[$found_cmd]}"
else
_Dbg_errmsg "Undefined command: \"$dbg_cmd\". Try \"help\"."
return 1
fi
;;
esac
fi
fi
aliases_found=''
_Dbg_alias_find_aliased "$dbg_cmd"
if [[ -n $aliases_found ]] ; then
_Dbg_msg ''
_Dbg_msg "Aliases for $dbg_cmd: $aliases_found"
fi
return 2
fi
}
_Dbg_alias_add 'h' help
_Dbg_alias_add '?' help
# Demo it.
if [[ $0 == ${BASH_SOURCE[0]} ]] ; then
for file in sort columnize list msg ; do
source "$top_dir/lib/${file}.sh";
done
# source /usr/local/share/bashdb/bashdb-trace
# _Dbg_debugger
_Dbg_do_help
echo '---'
_Dbg_args='help'
_Dbg_do_help help
fi
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.