mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 11:22:45 +08:00
Fix broken 'type' function, and clean up the ugly 'help' function. By Philip Ganchev.
darcs-hash:20060117165613-ac50b-b68c1b17708f01d9550dab242778f19590a3711d.gz
This commit is contained in:
parent
fd78f67d35
commit
d5f4df15d4
|
@ -70,6 +70,7 @@ function contains -d "Test if a key is contained in a set of values"
|
|||
return $status
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
# help should use 'open' to find a suitable browser, but only
|
||||
# if there is a mime database _and_ DISPLAY is set, since the
|
||||
|
@ -81,20 +82,22 @@ end
|
|||
function help -d "Show help for the fish shell"
|
||||
|
||||
# Declare variables to set correct scope
|
||||
|
||||
set fish_browser
|
||||
set fish_browser_bg
|
||||
|
||||
set -l h syntax completion editor job-control todo bugs history killring help
|
||||
set h $h color prompt title variables builtin-overview changes expand
|
||||
set h $h expand-variable expand-home expand-brace expand-wildcard
|
||||
set -l help_topics $h expand-command-substitution expand-process
|
||||
|
||||
#
|
||||
# Find a suitable browser for viewing the help pages. This is needed
|
||||
# by the help function defined below.
|
||||
#
|
||||
|
||||
set graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape
|
||||
set text_browsers htmlview www-browser links elinks lynx w3m
|
||||
|
||||
if test $BROWSER
|
||||
|
||||
# User has manualy set a preferred browser, so we respect that
|
||||
set fish_browser $BROWSER
|
||||
|
||||
|
@ -102,9 +105,7 @@ function help -d "Show help for the fish shell"
|
|||
if contains -- $BROWSER $graphical_browsers
|
||||
set fish_browser_bg 1
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
# Check for a text-based browser.
|
||||
for i in $text_browsers
|
||||
if which $i 2>/dev/null >/dev/null
|
||||
|
@ -113,8 +114,8 @@ function help -d "Show help for the fish shell"
|
|||
end
|
||||
end
|
||||
|
||||
# If we are in a graphical environment, we check if there is a
|
||||
# graphical browser to use instead.
|
||||
# If we are in a graphical environment, check if there is a graphical
|
||||
# browser to use instead.
|
||||
if test (echo $DISPLAY) -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
|
||||
for i in $graphical_browsers
|
||||
if which $i 2>/dev/null >/dev/null
|
||||
|
@ -132,41 +133,24 @@ function help -d "Show help for the fish shell"
|
|||
return 1
|
||||
end
|
||||
|
||||
if count $argv >/dev/null
|
||||
set fish_help_item $argv[1]
|
||||
end
|
||||
set fish_help_page ""
|
||||
|
||||
if test "$fish_help_item" = .
|
||||
switch "$fish_help_item"
|
||||
case ""
|
||||
set fish_help_page index.html
|
||||
case "."
|
||||
set fish_help_page "builtins.html\#source"
|
||||
end
|
||||
|
||||
if test "$fish_help_item" = difference
|
||||
case difference
|
||||
set fish_help_page difference.html
|
||||
end
|
||||
|
||||
if test "$fish_help_item" = globbing
|
||||
case globbing
|
||||
set fish_help_page "index.html\#expand"
|
||||
end
|
||||
|
||||
if contains -- $fish_help_item (builtin -n)
|
||||
case (builtin -n)
|
||||
set fish_help_page "builtins.html\#"$fish_help_item
|
||||
end
|
||||
|
||||
if contains -- $fish_help_item count dirh dirs help mimedb nextd open popd prevd pushd set_color tokenize psub umask type
|
||||
case count dirh dirs help mimedb nextd open popd prevd pushd set_color tokenize psub umask type
|
||||
set fish_help_page "commands.html\#"$fish_help_item
|
||||
end
|
||||
|
||||
set idx_subj syntax completion editor job-control todo bugs history
|
||||
set idx_subj $idx_subj killring help color prompt title variables
|
||||
set idx_subj $idx_subj builtin-overview changes
|
||||
set idx_subj $idx_subj expand expand-variable expand-home expand-brace expand-wildcard expand-command-substitution expand-process
|
||||
|
||||
if contains -- $fish_help_item $idx_subj
|
||||
case $help_topics
|
||||
set fish_help_page "index.html\#"$fish_help_item
|
||||
end
|
||||
|
||||
if not test $fish_help_page
|
||||
case "*"
|
||||
if which $fish_help_item >/dev/null ^/dev/null
|
||||
man $fish_help_item
|
||||
return
|
||||
|
@ -179,7 +163,6 @@ function help -d "Show help for the fish shell"
|
|||
else
|
||||
eval $fish_browser file://$__fish_help_dir/$fish_help_page
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -707,16 +690,18 @@ end
|
|||
|
||||
function type -d "Print the type of a command"
|
||||
|
||||
# Initialize
|
||||
set status 1
|
||||
set mode normal
|
||||
set selection all
|
||||
|
||||
|
||||
# Get options
|
||||
#
|
||||
set -- shortopt -o tpPafh
|
||||
if getopt -T >/dev/null
|
||||
set longopt
|
||||
else
|
||||
set longopt -- -l type,path,force-path,all,no-functions,help
|
||||
set -- longopt -l type,path,force-path,all,no-functions,help
|
||||
end
|
||||
|
||||
if not getopt -n type -Q $shortopt $longopt -- $argv
|
||||
|
@ -725,7 +710,7 @@ function type -d "Print the type of a command"
|
|||
|
||||
set -- tmp (getopt $shortopt $longopt -- $argv)
|
||||
|
||||
eval set opt -- $tmp
|
||||
eval set -- opt $tmp
|
||||
|
||||
for i in $opt
|
||||
switch $i
|
||||
|
@ -755,6 +740,7 @@ function type -d "Print the type of a command"
|
|||
end
|
||||
end
|
||||
|
||||
# Check all possible types for the remaining arguments
|
||||
for i in $argv
|
||||
|
||||
switch $i
|
||||
|
@ -776,7 +762,7 @@ function type -d "Print the type of a command"
|
|||
functions $i
|
||||
|
||||
case type
|
||||
printf (_ function)
|
||||
printf (_ 'function\n')
|
||||
|
||||
case path
|
||||
echo
|
||||
|
@ -815,7 +801,7 @@ function type -d "Print the type of a command"
|
|||
printf (_ '%s is %s\n') $i (which $i)
|
||||
|
||||
case type
|
||||
printf (_ file)
|
||||
printf (_ 'file\n')
|
||||
|
||||
case path
|
||||
which $i
|
||||
|
|
Loading…
Reference in New Issue
Block a user