function help --description 'Show help for the fish shell' set -l options h/help argparse -n help $options -- $argv or return if set -q _flag_help __fish_print_help help return 0 end set -l fish_help_item $argv[1] if test (count $argv) -gt 1 if string match -q string $argv[1] set fish_help_item (string join '-' $argv[1] $argv[2]) else echo "help: Expected at most 1 args, got 2" return 1 end end # Find a suitable browser for viewing the help pages. # The first thing we try is $fish_help_browser. set -l fish_browser $fish_help_browser # A list of graphical browsers we know about. set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla set -a graphical_browsers konqueror epiphany opera netscape rekonq google-chrome chromium-browser # 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 if not set -q fish_browser[1] if set -q BROWSER # User has manually set a preferred browser, so we respect that echo $BROWSER | read -at fish_browser else # No browser set up, inferring. # We check a bunch and use the last we find. # Check for a text-based browser. for i in htmlview www-browser links elinks lynx w3m 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 -n "$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 we have an open _command_ we use it - otherwise it's our function, # which might not have a backend to use. # Note that we prefer xdg-open, because this open might also be a symlink to "openvt" # like it is on Debian. if command -sq open set fish_browser open # The open command needs a trampoline because the macOS version can't handle #-fragments. set need_trampoline 1 end # If the OS appears to be Windows (graphical), try to use cygstart if type -q cygstart set fish_browser cygstart # If xdg-open is available, just use that else if type -q xdg-open set fish_browser xdg-open end # Try to find cmd.exe via $PATH or one of the paths that it's often at. # # We use this instead of xdg-open because that's useless without a backend # like wsl-open which we'll check in a minute. if test -f /proc/version and string match -riq 'Microsoft|WSL|MSYS|MINGW' ' >$tmpname set page_url file://$tmpname # For Windows (Cygwin, msys2 and WSL), we need to convert the base help dir to a Windows path before converting it to a file URL # but only if a Windows browser is being used if type -q cygpath and string match -qr '(cygstart|\.exe)(\s+|$)' $fish_browser[1] set page_url file://(cygpath -m $tmpname) else if type -q wslpath and string match -qr '\.exe(\s+|$)' $fish_browser[1] set page_url file://(wslpath -w $tmpname) end end end # cmd.exe needs more coaxing. if string match -qr 'cmd\.exe$' -- $fish_browser[1] # The space before the /c is to prevent msys2 from expanding it to a path $fish_browser " /c" start $page_url # If browser is known to be graphical, put into background else if contains -- $fish_browser[1] $graphical_browsers 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 $fish_browser $page_url & disown $last_pid >/dev/null 2>&1 else # Work around lynx bug where