mirror of
https://github.com/jorgebucaran/fisher
synced 2024-09-10 15:07:40 +02:00
Add new __fisher_help_* functions.
Split help command functionality into individual functions for cosistent with the way other commands are structured, and improve tab completion times by skipping the overhead of calling fisher_help directly.
This commit is contained in:
parent
c74d55f35b
commit
93eae8a341
4 changed files with 58 additions and 48 deletions
20
functions/__fisher_help_commands.fish
Normal file
20
functions/__fisher_help_commands.fish
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
function __fisher_help_commands
|
||||||
|
for i in (functions -a | grep -E '^fisher_[^_]+$')
|
||||||
|
functions $i | awk '
|
||||||
|
|
||||||
|
/^$/ { next } {
|
||||||
|
printf("%s;", substr($2, 8))
|
||||||
|
|
||||||
|
gsub("\'", "")
|
||||||
|
|
||||||
|
for (i = 4; i <= NF && $i !~ /^--.*/; i++) {
|
||||||
|
printf("%s ", $i)
|
||||||
|
}
|
||||||
|
|
||||||
|
print ""
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
'
|
||||||
|
end
|
||||||
|
end
|
4
functions/__fisher_help_guides.fish
Normal file
4
functions/__fisher_help_guides.fish
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
function __fisher_help_guides
|
||||||
|
sed -nE 's/(fisher-)?(.+)\([0-9]\) -- (.+)/\2;\3/p' \
|
||||||
|
{$fisher_home,$fisher_config}/man/man{5,7}/fisher*.md | sort -r
|
||||||
|
end
|
14
functions/__fisher_help_usage.fish
Normal file
14
functions/__fisher_help_usage.fish
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
function __fisher_help_usage -a value
|
||||||
|
if test -z "$value"
|
||||||
|
set -e value
|
||||||
|
sed -E 's/^ *([^ ]+).*/\1/' | while read -l command
|
||||||
|
if functions -q fisher_$command
|
||||||
|
set value $command $value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for command in $value
|
||||||
|
fisher $command -h
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@ function fisher_help -d "Show Help"
|
||||||
getopts $argv | while read -l 1 2
|
getopts $argv | while read -l 1 2
|
||||||
switch "$1"
|
switch "$1"
|
||||||
case _
|
case _
|
||||||
set option manual
|
set option man
|
||||||
set value $2
|
set value $2
|
||||||
|
|
||||||
case a all
|
case a all
|
||||||
|
@ -25,7 +25,7 @@ function fisher_help -d "Show Help"
|
||||||
set option $option commands
|
set option $option commands
|
||||||
set value $2
|
set value $2
|
||||||
|
|
||||||
case u usage
|
case usage
|
||||||
set option usage
|
set option usage
|
||||||
set value $value $2
|
set value $value $2
|
||||||
|
|
||||||
|
@ -35,15 +35,15 @@ function fisher_help -d "Show Help"
|
||||||
case h
|
case h
|
||||||
printf "Usage: fisher help [<keyword>] [--all] [--guides] [--help]\n\n"
|
printf "Usage: fisher help [<keyword>] [--all] [--guides] [--help]\n\n"
|
||||||
|
|
||||||
printf " -a --all List available documentation\n"
|
printf " -a --all List available documentation\n"
|
||||||
printf " -g --guides List available guides\n"
|
printf " -g --guides List available guides\n"
|
||||||
printf " -u --usage[=<cmd>] Display command usage\n"
|
printf " --usage[=<cmd>] Display command usage\n"
|
||||||
printf " -h --help Show usage help\n"
|
printf " -h --help Show usage help\n"
|
||||||
return
|
return
|
||||||
|
|
||||||
case \*
|
case \*
|
||||||
printf "fisher: '%s' is not a valid option.\n" $1 > /dev/stderr
|
printf "fisher: '%s' is not a valid option.\n" $1 > /dev/stderr
|
||||||
fisher_help --help > /dev/stderr
|
fisher_help -h > /dev/stderr
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -56,7 +56,7 @@ function fisher_help -d "Show Help"
|
||||||
case help
|
case help
|
||||||
man fisher-help
|
man fisher-help
|
||||||
|
|
||||||
case manual
|
case man
|
||||||
set -l value (printf "%s\n" $value | awk '{ print tolower($0) }')
|
set -l value (printf "%s\n" $value | awk '{ print tolower($0) }')
|
||||||
|
|
||||||
switch "$value"
|
switch "$value"
|
||||||
|
@ -68,50 +68,22 @@ function fisher_help -d "Show Help"
|
||||||
end
|
end
|
||||||
|
|
||||||
case usage
|
case usage
|
||||||
if test -z "$value"
|
__fisher_help_usage $value
|
||||||
set -e value
|
|
||||||
sed -E 's/^ *([^ ]+).*/\1/' | while read -l command
|
|
||||||
if functions -q fisher_$command
|
|
||||||
set value $command $value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for command in $value
|
|
||||||
fisher $command -h
|
|
||||||
end
|
|
||||||
|
|
||||||
case \*
|
case \*
|
||||||
switch "$value"
|
if test "$value" != bare
|
||||||
case bare
|
fisher --help=$option
|
||||||
case \*
|
return
|
||||||
fisher --help=$option
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
switch commands
|
begin
|
||||||
case $option
|
if contains -- commands $option
|
||||||
functions -a | grep '^fisher_[^_]*$' | while read -l func
|
__fisher_help_commands
|
||||||
functions $func | awk '
|
end
|
||||||
/^$/ { next } {
|
|
||||||
printf(" %s\t", substr($2, 8))
|
|
||||||
gsub("\'","")
|
|
||||||
|
|
||||||
for (i=4; i<=NF && $i!~/^--.*/; i++) {
|
if contains -- guides $option
|
||||||
printf("%s ", $i)
|
__fisher_help_guides
|
||||||
}
|
end
|
||||||
|
end | sed 's/^/ /;s/;/'\t'/' | column -ts\t
|
||||||
print ""
|
|
||||||
exit
|
|
||||||
}'
|
|
||||||
end | column -ts\t
|
|
||||||
end
|
|
||||||
|
|
||||||
switch guides
|
|
||||||
case $option
|
|
||||||
sed -nE 's/(fisher-)?(.+)\([0-9]\) -- (.+)/ \2'\t'\3/p' \
|
|
||||||
{$fisher_home,$fisher_config}/man/man{5,7}/fisher*.md | sort -r
|
|
||||||
|
|
||||||
end | column -ts\t
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue