]> arthur.barton.de Git - ax-zsh.git/blob - plugins/browser_select/browser_select.zprofile
1f45a24a65c9ff61f4f5f3bb8bf1b674fea5d6d0
[ax-zsh.git] / plugins / browser_select / browser_select.zprofile
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # browser_select.zprofile: Setup $BROWSER for the "best" available WWW browser
3
4 # Don't run this plugin on "check-plugins"!
5 [[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
6
7
8 if [[ -z "$BROWSER" ]]; then
9         if [[ "$OSTYPE" != "linux-gnu" ]]; then
10                 # Check for open(1) on Non-Linux systems. On (Debian-) Linux, the open(1)
11                 # command would recursively call $BROWSER (=itself) ...
12                 open_browsers="open"
13         fi
14         if [[ -n "$DISPLAY" ]]; then
15                 # X11 available, consider X11-based browsers, too!
16                 x11_browsers="firefox chrome"
17         fi
18
19         # Note: We can't use xdg-open(1) here, as xdg-open itself tries to use
20         # $BROWSER, and this would result in an endless loop!
21         for browser (
22                 $open_browsers
23                 $x11_browsers
24                 elinks w3m links2 links lynx
25         ); do
26                 if [[ -n "$commands[$browser]" ]]; then
27                         BROWSER="$commands[$browser]"
28                         break
29                 fi
30         done
31         unset browser open_browser x11_browsers
32 fi
33
34 [[ -n "$BROWSER" ]] && export BROWSER