2012-12-27 22:04:11 +00:00
|
|
|
function help --description 'Show help for the fish shell'
|
|
|
|
|
2006-02-08 09:20:05 +00: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 02:18:26 +00: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 09:20:05 +00:00
|
|
|
|
2006-08-22 00:52:30 +00:00
|
|
|
# 'help -h' should launch 'help help'
|
2006-09-04 20:16:12 +00:00
|
|
|
if count $argv >/dev/null
|
|
|
|
switch $argv[1]
|
|
|
|
case -h --h --he --hel --help
|
2006-11-17 16:24:38 +00:00
|
|
|
__fish_print_help help
|
|
|
|
return 0
|
2006-09-04 20:16:12 +00:00
|
|
|
end
|
2006-08-22 00:52:30 +00:00
|
|
|
end
|
|
|
|
|
2006-02-08 09:20:05 +00:00
|
|
|
#
|
|
|
|
# Find a suitable browser for viewing the help pages. This is needed
|
|
|
|
# by the help function defined below.
|
|
|
|
#
|
2013-05-25 20:52:06 +00:00
|
|
|
set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
|
2006-02-08 09:20:05 +00:00
|
|
|
set -l text_browsers htmlview www-browser links elinks lynx w3m
|
|
|
|
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q "$BROWSER"
|
2013-05-25 20:52:06 +00:00
|
|
|
# User has manually set a preferred browser, so we respect that
|
2006-02-08 09:20:05 +00:00
|
|
|
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
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f $i
|
2006-02-08 09:20:05 +00: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
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f $i
|
2006-02-08 09:20:05 +00:00
|
|
|
set fish_browser $i
|
|
|
|
set fish_browser_bg 1
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-05-20 19:58:03 +00:00
|
|
|
|
2013-08-13 14:26:38 +00:00
|
|
|
# If the OS appears to be Windows (graphical), try to use cygstart
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q cygstart
|
2013-08-13 14:26:38 +00:00
|
|
|
set fish_browser cygstart
|
2012-08-25 20:02:58 +00:00
|
|
|
# If xdg-open is available, just use that
|
2014-07-10 07:26:58 +00:00
|
|
|
else if type -q xdg-open
|
2012-08-25 20:02:58 +00:00
|
|
|
set fish_browser xdg-open
|
|
|
|
end
|
2012-12-27 22:04:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
# On OS X, we go through osascript by default
|
2012-05-20 19:58:03 +00:00
|
|
|
if test (uname) = Darwin
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q osascript
|
2012-12-27 22:04:11 +00:00
|
|
|
set fish_browser osascript
|
|
|
|
end
|
2012-05-20 19:58:03 +00:00
|
|
|
end
|
|
|
|
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if test -z $fish_browser
|
|
|
|
printf (_ '%s: Could not find a web browser.\n') help
|
2013-05-25 20:52:06 +00:00
|
|
|
printf (_ 'Please set the variable $BROWSER to a suitable browser and try again.\n\n')
|
2006-02-08 09:20:05 +00:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2016-02-09 15:08:57 +00:00
|
|
|
# In Cygwin, start the user-specified browser using cygstart
|
|
|
|
if type -q cygstart
|
|
|
|
if test $fish_browser != "cygstart"
|
|
|
|
# Escaped quotes are necessary to work with spaces in the path
|
|
|
|
# when the command is finally eval'd.
|
|
|
|
set fish_browser cygstart \"$fish_browser\"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-10 01:46:14 +00:00
|
|
|
set -l fish_help_item $argv[1]
|
2006-02-08 09:20:05 +00:00
|
|
|
|
|
|
|
switch "$fish_help_item"
|
|
|
|
case ""
|
|
|
|
set fish_help_page index.html
|
|
|
|
case "."
|
2006-11-07 13:12:11 +00:00
|
|
|
set fish_help_page "commands.html\#source"
|
2006-02-08 09:20:05 +00:00
|
|
|
case globbing
|
|
|
|
set fish_help_page "index.html\#expand"
|
2012-12-27 06:08:49 +00:00
|
|
|
case (__fish_print_commands)
|
2006-02-08 09:20:05 +00:00
|
|
|
set fish_help_page "commands.html\#$fish_help_item"
|
|
|
|
case $help_topics
|
|
|
|
set fish_help_page "index.html\#$fish_help_item"
|
|
|
|
case "*"
|
2014-07-10 07:26:58 +00:00
|
|
|
if type -q -f $fish_help_item
|
2012-07-10 01:46:14 +00: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"
|
2012-12-27 21:39:43 +00:00
|
|
|
if test -f "$man_arg"
|
|
|
|
man $man_arg
|
|
|
|
return
|
2012-07-10 01:46:14 +00:00
|
|
|
end
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|
|
|
|
set fish_help_page "index.html"
|
|
|
|
end
|
2012-12-27 21:39:43 +00:00
|
|
|
|
|
|
|
set -l page_url
|
|
|
|
if test -f $__fish_help_dir/index.html
|
|
|
|
# Help is installed, use it
|
|
|
|
set page_url file://$__fish_help_dir/$fish_help_page
|
2016-02-09 15:08:57 +00:00
|
|
|
|
|
|
|
# In Cygwin, we need to convert the base help dir to a Windows path before converting it to a file URL
|
|
|
|
if type -q cygpath
|
|
|
|
set page_url file://(cygpath -m $__fish_help_dir)/$fish_help_page
|
|
|
|
end
|
2012-12-27 21:39:43 +00:00
|
|
|
else
|
|
|
|
# Go to the web. Only include one dot in the version string
|
|
|
|
set -l version_string (echo $FISH_VERSION| cut -d . -f 1,2)
|
|
|
|
set page_url http://fishshell.com/docs/$version_string/$fish_help_page
|
|
|
|
end
|
|
|
|
|
2012-12-27 22:04:11 +00:00
|
|
|
# OS X /usr/bin/open swallows fragments (anchors), so use osascript
|
|
|
|
# Eval is just a cheesy way of removing the hash escaping
|
|
|
|
if test "$fish_browser" = osascript
|
|
|
|
osascript -e 'open location "'(eval echo $page_url)'"'
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2006-02-08 09:20:05 +00:00
|
|
|
if test $fish_browser_bg
|
2006-08-14 18:11:35 +00:00
|
|
|
|
|
|
|
switch $fish_browser
|
|
|
|
case 'htmlview' 'x-www-browser'
|
2013-05-25 20:52:06 +00:00
|
|
|
printf (_ 'help: Help is being displayed in your default browser.\n')
|
2006-08-14 18:11:35 +00:00
|
|
|
|
|
|
|
case '*'
|
2013-05-25 20:52:06 +00:00
|
|
|
printf (_ 'help: Help is being displayed in %s.\n') $fish_browser
|
2006-08-14 18:11:35 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2012-12-27 21:39:43 +00:00
|
|
|
eval "$fish_browser $page_url &"
|
2006-02-08 09:20:05 +00:00
|
|
|
else
|
2012-12-27 21:39:43 +00:00
|
|
|
eval $fish_browser $page_url
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|
|
|
|
end
|