mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-26 11:45:08 +00:00
Allow browser for help to be chosen indenpendent of $BROWSER.
This commit is contained in:
parent
ed5f90d22e
commit
5ec9fcd8d4
2 changed files with 43 additions and 44 deletions
|
@ -13,6 +13,8 @@ If a `SECTION` is specified, the help for that command is shown.
|
||||||
|
|
||||||
If the BROWSER environment variable is set, it will be used to display the documentation. Otherwise, fish will search for a suitable browser.
|
If the BROWSER environment variable is set, it will be used to display the documentation. Otherwise, fish will search for a suitable browser.
|
||||||
|
|
||||||
|
If you prefer to use a different browser (other than as described above) for fish help, you can set the fish_help_browser variable. This variable may be set as an array, where the first element is the browser command and the rest are browser options.
|
||||||
|
|
||||||
Note that most builtin commands display their help in the terminal when given the `--help` option.
|
Note that most builtin commands display their help in the terminal when given the `--help` option.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ function help --description 'Show help for the fish shell'
|
||||||
|
|
||||||
# Declare variables to set correct scope
|
# Declare variables to set correct scope
|
||||||
set -l fish_browser
|
set -l fish_browser
|
||||||
set -l fish_browser_bg
|
|
||||||
|
|
||||||
set -l h syntax completion editor job-control todo bugs history killring help
|
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 color prompt title variables builtin-overview changes expand
|
||||||
|
@ -23,58 +22,58 @@ function help --description 'Show help for the fish shell'
|
||||||
# by the help function defined below.
|
# by the help function defined below.
|
||||||
#
|
#
|
||||||
set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
|
set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser
|
||||||
set -l text_browsers htmlview www-browser links elinks lynx w3m
|
|
||||||
|
|
||||||
if type -q "$BROWSER"
|
if set -q fish_help_browser[1]
|
||||||
# User has manually set a preferred browser, so we respect that
|
# User has set a fish-specific help browser. This overrides the
|
||||||
set fish_browser $BROWSER
|
# browser that may be defined by $BROWSER. The fish_help_browser
|
||||||
|
# variable may be an array containing a browser name plus options.
|
||||||
# If browser is known to be graphical, put into background
|
set fish_browser $fish_help_browser
|
||||||
if contains -- $BROWSER $graphical_browsers
|
|
||||||
set fish_browser_bg 1
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
# Check for a text-based browser.
|
set -l text_browsers htmlview www-browser links elinks lynx w3m
|
||||||
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
|
if set -q BROWSER
|
||||||
# browser to use instead.
|
# User has manually set a preferred browser, so we respect that
|
||||||
if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
|
set fish_browser $BROWSER
|
||||||
for i in $graphical_browsers
|
else
|
||||||
|
# Check for a text-based browser.
|
||||||
|
for i in $text_browsers
|
||||||
if type -q -f $i
|
if type -q -f $i
|
||||||
set fish_browser $i
|
set fish_browser $i
|
||||||
set fish_browser_bg 1
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# If the OS appears to be Windows (graphical), try to use cygstart
|
# If we are in a graphical environment, check if there is a graphical
|
||||||
if type -q cygstart
|
# browser to use instead.
|
||||||
set fish_browser cygstart
|
if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \)
|
||||||
# If xdg-open is available, just use that
|
for i in $graphical_browsers
|
||||||
else if type -q xdg-open
|
if type -q -f $i
|
||||||
set fish_browser xdg-open
|
set fish_browser $i
|
||||||
end
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
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
|
||||||
|
|
||||||
# On OS X, we go through osascript by default
|
# On OS X, we go through osascript by default
|
||||||
if test (uname) = Darwin
|
if test (uname) = Darwin
|
||||||
if type -q osascript
|
if type -q osascript
|
||||||
set fish_browser osascript
|
set fish_browser osascript
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if test -z $fish_browser
|
if not set -q fish_browser
|
||||||
printf (_ '%s: Could not find a web browser.\n') help
|
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')
|
printf (_ 'Please set the variable $BROWSER or fish_help_browser and try again.\n\n')
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -136,17 +135,15 @@ function help --description 'Show help for the fish shell'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if test $fish_browser_bg
|
|
||||||
|
|
||||||
switch $fish_browser
|
# If browser is known to be graphical, put into background
|
||||||
|
if contains -- $fish_browser[1] $graphical_browsers
|
||||||
|
switch $fish_browser[1]
|
||||||
case 'htmlview' 'x-www-browser'
|
case 'htmlview' 'x-www-browser'
|
||||||
printf (_ 'help: Help is being displayed in your default browser.\n')
|
printf (_ 'help: Help is being displayed in your default browser.\n')
|
||||||
|
|
||||||
case '*'
|
case '*'
|
||||||
printf (_ 'help: Help is being displayed in %s.\n') $fish_browser
|
printf (_ 'help: Help is being displayed in %s.\n') $fish_browser[1]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
eval "$fish_browser $page_url &"
|
eval "$fish_browser $page_url &"
|
||||||
else
|
else
|
||||||
eval $fish_browser $page_url
|
eval $fish_browser $page_url
|
||||||
|
|
Loading…
Reference in a new issue