2012-12-28 06:04:11 +08:00
|
|
|
function help --description 'Show help for the fish shell'
|
2017-07-14 04:49:15 +08:00
|
|
|
set -l options 'h/help'
|
|
|
|
argparse -n help --max-args=1 $options -- $argv
|
|
|
|
or return
|
2016-11-28 13:27:22 +08:00
|
|
|
|
2017-07-14 04:49:15 +08:00
|
|
|
if set -q _flag_help
|
|
|
|
__fish_print_help help
|
|
|
|
return 0
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
|
|
|
|
2017-07-14 04:49:15 +08:00
|
|
|
set -l fish_help_item $argv[1]
|
|
|
|
set -l help_topics syntax completion editor job-control todo bugs history killring help
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a help_topics color prompt title variables builtin-overview changes expand
|
|
|
|
set -a help_topics expand-variable expand-home expand-brace expand-wildcard
|
|
|
|
set -a help_topics expand-command-substitution expand-process
|
2017-07-14 04:49:15 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
#
|
|
|
|
# Find a suitable browser for viewing the help pages. This is needed
|
|
|
|
# by the help function defined below.
|
|
|
|
#
|
2017-07-14 04:49:15 +08:00
|
|
|
set -l fish_browser
|
2016-11-28 13:27:22 +08:00
|
|
|
set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
|
|
|
|
|
2018-01-13 07:02:13 +08:00
|
|
|
# On mac we may have to write a temporary file that redirects to the desired
|
|
|
|
# help page, since `open` will drop fragments from file URIs (issue #4480).
|
|
|
|
set -l need_trampoline
|
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
if set -q fish_help_browser[1]
|
|
|
|
# User has set a fish-specific help browser. This overrides the
|
|
|
|
# browser that may be defined by $BROWSER. The fish_help_browser
|
|
|
|
# variable may be an array containing a browser name plus options.
|
|
|
|
set fish_browser $fish_help_browser
|
|
|
|
else
|
|
|
|
set -l text_browsers htmlview www-browser links elinks lynx w3m
|
|
|
|
|
|
|
|
if set -q BROWSER
|
|
|
|
# User has manually set a preferred browser, so we respect that
|
|
|
|
set fish_browser $BROWSER
|
|
|
|
else
|
|
|
|
# Check for a text-based browser.
|
|
|
|
for i in $text_browsers
|
|
|
|
if type -q -f $i
|
|
|
|
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
|
|
|
|
if type -q -f $i
|
|
|
|
set fish_browser $i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# If the OS appears to be Windows (graphical), try to use cygstart
|
|
|
|
if type -q cygstart
|
|
|
|
set fish_browser cygstart
|
2017-09-27 02:25:29 +08:00
|
|
|
# If xdg-open is available, just use that
|
|
|
|
# but only if an X session is running
|
|
|
|
else if type -q xdg-open; and set -q -x DISPLAY
|
2016-11-28 13:27:22 +08:00
|
|
|
set fish_browser xdg-open
|
|
|
|
end
|
|
|
|
|
2018-01-13 07:02:13 +08:00
|
|
|
# On OS X, we go through open by default
|
2016-11-28 13:27:22 +08:00
|
|
|
if test (uname) = Darwin
|
2018-01-13 07:02:13 +08:00
|
|
|
if type -q open
|
|
|
|
set fish_browser open
|
|
|
|
set need_trampoline 1
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-19 04:48:41 +08:00
|
|
|
if not set -q fish_browser[1]
|
2016-11-28 13:27:22 +08:00
|
|
|
printf (_ '%s: Could not find a web browser.\n') help
|
|
|
|
printf (_ 'Please set the variable $BROWSER or fish_help_browser and try again.\n\n')
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
switch "$fish_help_item"
|
|
|
|
case "."
|
2018-01-13 06:58:28 +08:00
|
|
|
set fish_help_page "commands.html\#source"
|
2016-11-28 13:27:22 +08:00
|
|
|
case globbing
|
2018-01-13 06:58:28 +08:00
|
|
|
set fish_help_page "index.html\#expand"
|
2016-11-28 13:27:22 +08:00
|
|
|
case (__fish_print_commands)
|
2018-01-13 06:58:28 +08:00
|
|
|
set fish_help_page "commands.html\#$fish_help_item"
|
2016-11-28 13:27:22 +08:00
|
|
|
case $help_topics
|
2018-01-13 06:58:28 +08:00
|
|
|
set fish_help_page "index.html\#$fish_help_item"
|
2017-06-14 19:52:24 +08:00
|
|
|
case 'tut_*'
|
2018-01-13 06:58:28 +08:00
|
|
|
set fish_help_page "tutorial.html\#$fish_help_item"
|
2017-06-14 19:52:24 +08:00
|
|
|
case tutorial
|
|
|
|
set fish_help_page "tutorial.html"
|
2016-11-28 13:27:22 +08:00
|
|
|
case "*"
|
2017-06-14 19:52:24 +08:00
|
|
|
# If $fish_help_item is empty, this will fail,
|
|
|
|
# and $fish_help_page will end up as index.html
|
2017-08-12 00:27:58 +08:00
|
|
|
if type -q -f "$fish_help_item"
|
2016-11-28 13:27:22 +08:00
|
|
|
# Prefer to use fish's man pages, to avoid
|
|
|
|
# the annoying useless "builtin" man page bash
|
|
|
|
# installs on OS X
|
2018-03-12 21:34:20 +08:00
|
|
|
set -l man_arg "$__fish_data_dir/man/man1/$fish_help_item.1"
|
2016-11-28 13:27:22 +08:00
|
|
|
if test -f "$man_arg"
|
|
|
|
man $man_arg
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
set fish_help_page "index.html"
|
|
|
|
end
|
|
|
|
|
2018-04-03 07:36:11 +08:00
|
|
|
set -l wsl 0
|
|
|
|
if uname -a | string match -qr Microsoft
|
|
|
|
set wsl 1
|
|
|
|
end
|
|
|
|
|
2016-11-28 13:27:22 +08: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
|
|
|
|
|
|
|
|
# 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
|
|
|
|
else
|
|
|
|
# Go to the web. Only include one dot in the version string
|
2017-10-14 23:29:16 +08:00
|
|
|
set -l version_string (echo $version| cut -d . -f 1,2)
|
2017-02-17 21:30:43 +08:00
|
|
|
set page_url https://fishshell.com/docs/$version_string/$fish_help_page
|
2018-01-13 07:02:13 +08:00
|
|
|
# We don't need a trampoline for a remote URL.
|
|
|
|
set need_trampoline
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
|
|
|
|
2018-01-13 07:02:13 +08:00
|
|
|
if set -q need_trampoline[1]
|
|
|
|
# If string replace doesn't replace anything, we don't actually need a
|
|
|
|
# trampoline (they're only needed if there's a fragment in the path)
|
|
|
|
if set -l clean_url (string replace '\\#' '#' $page_url)
|
|
|
|
# Write a temporary file that will redirect where we want.
|
|
|
|
set -q TMPDIR
|
|
|
|
or set -l TMPDIR /tmp
|
|
|
|
set -l tmpdir (mktemp -d $TMPDIR/help.XXXXXX)
|
|
|
|
set -l tmpname $tmpdir/help.html
|
|
|
|
echo '<meta http-equiv="refresh" content="0;URL=\''$clean_url'\'" />' > $tmpname
|
|
|
|
set page_url file://$tmpname
|
|
|
|
end
|
2018-01-13 06:58:28 +08:00
|
|
|
end
|
|
|
|
|
2018-04-03 07:36:11 +08:00
|
|
|
if test $wsl -eq 1
|
|
|
|
cmd.exe /c "start $page_url"
|
2016-11-28 13:27:22 +08:00
|
|
|
# If browser is known to be graphical, put into background
|
2018-04-03 07:36:11 +08:00
|
|
|
else if contains -- $fish_browser[1] $graphical_browsers
|
2016-11-28 13:27:22 +08:00
|
|
|
switch $fish_browser[1]
|
|
|
|
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[1]
|
|
|
|
end
|
2018-10-21 21:33:29 +08:00
|
|
|
$fish_browser $page_url &
|
2016-11-28 13:27:22 +08:00
|
|
|
else
|
2017-09-27 02:34:23 +08:00
|
|
|
# Work around lynx bug where <div class="contents"> always has the same formatting as links (unreadable)
|
|
|
|
# by using a custom style sheet. See https://github.com/fish-shell/fish-shell/issues/4170
|
|
|
|
set -l local_file 0
|
2018-10-21 21:33:29 +08:00
|
|
|
if $fish_browser --version 2>/dev/null | string match -qr Lynx
|
2018-03-12 21:34:20 +08:00
|
|
|
set fish_browser $fish_browser -lss={$__fish_data_dir}/lynx.lss
|
2017-09-27 02:34:23 +08:00
|
|
|
end
|
2018-10-21 21:33:29 +08:00
|
|
|
$fish_browser $page_url
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|