2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# help should use 'open' to find a suitable browser, but only
|
|
|
|
# if there is a mime database _and_ DISPLAY is set, since the
|
|
|
|
# browser will most likely be graphical. Since most systems which
|
|
|
|
# have a mime databe also have the htmlview program, this is mostly a
|
|
|
|
# theoretical problem.
|
|
|
|
#
|
|
|
|
|
2007-01-16 09:29:18 +08:00
|
|
|
function help --description "Show help for the fish shell"
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
# Declare variables to set correct scope
|
|
|
|
set -l fish_browser
|
|
|
|
set -l fish_browser_bg
|
|
|
|
|
|
|
|
set -l h syntax completion editor job-control todo bugs history killring help
|
2010-09-18 10:18:26 +08:00
|
|
|
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
|
2006-02-08 17:20:05 +08:00
|
|
|
|
2006-08-22 08:52:30 +08:00
|
|
|
# 'help -h' should launch 'help help'
|
2006-09-05 04:16:12 +08:00
|
|
|
if count $argv >/dev/null
|
|
|
|
switch $argv[1]
|
|
|
|
case -h --h --he --hel --help
|
2006-11-18 00:24:38 +08:00
|
|
|
__fish_print_help help
|
|
|
|
return 0
|
2006-09-05 04:16:12 +08:00
|
|
|
end
|
2006-08-22 08:52:30 +08:00
|
|
|
end
|
|
|
|
|
2006-02-08 17:20:05 +08:00
|
|
|
#
|
|
|
|
# Find a suitable browser for viewing the help pages. This is needed
|
|
|
|
# by the help function defined below.
|
|
|
|
#
|
2012-06-08 23:41:26 +08:00
|
|
|
set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq
|
2006-02-08 17:20:05 +08:00
|
|
|
set -l 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
|
|
|
|
|
|
|
|
# If browser is known to be graphical, put into background
|
|
|
|
if contains -- $BROWSER $graphical_browsers
|
|
|
|
set fish_browser_bg 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
# Check for a text-based browser.
|
|
|
|
for i in $text_browsers
|
2006-03-14 08:21:27 +08:00
|
|
|
if type -f $i >/dev/null
|
2006-02-08 17:20:05 +08:00
|
|
|
set fish_browser $i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# If we are in a graphical environment, check if there is a graphical
|
|
|
|
# browser to use instead.
|
|
|
|
if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
|
|
|
|
for i in $graphical_browsers
|
2006-03-14 08:21:27 +08:00
|
|
|
if type -f $i >/dev/null
|
2006-02-08 17:20:05 +08:00
|
|
|
set fish_browser $i
|
|
|
|
set fish_browser_bg 1
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-05-21 03:58:03 +08:00
|
|
|
|
2012-08-26 04:02:58 +08:00
|
|
|
# If xdg-open is available, just use that
|
|
|
|
if type xdg-open > /dev/null
|
|
|
|
set fish_browser xdg-open
|
|
|
|
end
|
|
|
|
|
2012-05-21 03:58:03 +08:00
|
|
|
# On OS X, just use open
|
|
|
|
if test (uname) = Darwin
|
|
|
|
set fish_browser (which open)
|
|
|
|
end
|
|
|
|
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if test -z $fish_browser
|
|
|
|
printf (_ '%s: Could not find a web browser.\n') help
|
|
|
|
printf (_ 'Please set the variable $BROWSER to a suitable browser and try again\n\n')
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2012-07-10 09:46:14 +08:00
|
|
|
set -l fish_help_item $argv[1]
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
switch "$fish_help_item"
|
|
|
|
case ""
|
|
|
|
set fish_help_page index.html
|
|
|
|
case "."
|
2006-11-07 21:12:11 +08:00
|
|
|
set fish_help_page "commands.html\#source"
|
2006-02-08 17:20:05 +08:00
|
|
|
case difference
|
|
|
|
set fish_help_page difference.html
|
|
|
|
case globbing
|
|
|
|
set fish_help_page "index.html\#expand"
|
2006-05-29 21:32:39 +08:00
|
|
|
|
|
|
|
# This command substitution should locate all commands with
|
|
|
|
# documentation. It's a bit of a hack, since it relies on the
|
2006-11-07 21:12:11 +08:00
|
|
|
# Doxygen markup format to never change.
|
2006-05-29 21:32:39 +08:00
|
|
|
|
2012-12-17 22:50:00 +08:00
|
|
|
case (sed -n 's/.*<h[12]><a class="anchor" \(id\|name\)="\([^"]*\)">.*/\2/p' $__fish_help_dir/commands.html)
|
2006-02-08 17:20:05 +08:00
|
|
|
set fish_help_page "commands.html\#$fish_help_item"
|
|
|
|
case $help_topics
|
|
|
|
set fish_help_page "index.html\#$fish_help_item"
|
|
|
|
case "*"
|
2006-03-14 08:21:27 +08:00
|
|
|
if type -f $fish_help_item >/dev/null
|
2012-07-10 09:46:14 +08:00
|
|
|
# Prefer to use fish's man pages, to avoid
|
|
|
|
# the annoying useless "builtin" man page bash
|
|
|
|
# installs on OS X
|
|
|
|
set -l man_arg "$__fish_datadir/man/man1/$fish_help_item.1"
|
|
|
|
if test ! -f "$man_arg"
|
|
|
|
set man_arg $fish_help_item
|
|
|
|
end
|
|
|
|
man $man_arg
|
2006-02-08 17:20:05 +08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
set fish_help_page "index.html"
|
|
|
|
end
|
|
|
|
|
|
|
|
if test $fish_browser_bg
|
2006-08-15 02:11:35 +08:00
|
|
|
|
|
|
|
switch $fish_browser
|
|
|
|
case 'htmlview' 'x-www-browser'
|
|
|
|
printf (_ 'help: Help is being displayed in your default browser\n')
|
|
|
|
|
|
|
|
case '*'
|
|
|
|
printf (_ 'help: Help is being displayed in %s\n') $fish_browser
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-06-08 23:41:26 +08:00
|
|
|
eval "$fish_browser file://$__fish_help_dir/$fish_help_page &"
|
2006-02-08 17:20:05 +08:00
|
|
|
else
|
|
|
|
eval $fish_browser file://$__fish_help_dir/$fish_help_page
|
|
|
|
end
|
|
|
|
end
|