From f725cd402d0324b2660a1fda2ac299d5ac146593 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Mon, 1 Mar 2021 22:39:11 -0800 Subject: [PATCH] Make `help` and `fish_config` work on Chrome OS When `fish` is running in the Chrome OS Linux VM (Crostini), both `help` and `fish_config` opened a "file not found" page. That is because on Crostini, `BROWSER` is usually set to `garcon-url-handler`, which opens URLs in the host OS Chrome browser. That browser lacks access to the Linux file system. This commit fixes these commands. `help` now opens the URL on www.fishshell.com. `fish_config` now opens the URL for the server it starts. Previously, it opened a local file that redirects to the same URL. In the case of `help`, the situation could be improved further by starting a web server to serve help. I don't know of another way to access `/share/fish` from outside the VM without user intervention, and I think that might be a part of the security model for the Crostini VM. It's hard to write a test for this. I checked that `help math`, `python2 webconfig.py`, and `python3 webconfig.py` work on my machine running in Crostini. --- CHANGELOG.rst | 1 + share/functions/help.fish | 12 ++++++++++-- share/tools/web_config/webconfig.py | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 75e234e60..2389433e7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,7 @@ Scripting improvements Interactive improvements ------------------------ +- ``help`` and ``fish_config`` no longer open to a "Your file couldn't be accessed" page when fish is running in a Chrome OS Crostini Linux VM and URLs are opened in Chrome running outside the VM. New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/share/functions/help.fish b/share/functions/help.fish index 0fd612d08..71531babb 100644 --- a/share/functions/help.fish +++ b/share/functions/help.fish @@ -142,12 +142,20 @@ function help --description 'Show help for the fish shell' set fish_help_page "index.html#$fish_help_item" end + # In Crostini Chrome OS Linux, the default browser opens URLs in Chrome running outside the + # linux VM. This browser does not have access to the Linux filesystem. This uses Garcon, see e.g. + # https://chromium.googlesource.com/chromiumos/platform2/+/master/vm_tools/garcon/#opening-urls + # https://source.chromium.org/search?q=garcon-url-handler + string match -q '*garcon-url-handler*' $fish_browser[1] + and set -l chromeos_linux_garcon + set -l page_url - if test -f $__fish_help_dir/index.html + if test -f $__fish_help_dir/index.html; and not set -lq chromeos_linux_garcon # Help is installed, use it set page_url file://$__fish_help_dir/$fish_help_page - # 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 + # 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] diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index bfe33d1b9..cfddf73f4 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -71,6 +71,16 @@ def is_termux(): return "com.termux" in os.environ["PATH"] and find_executable("termux-open-url") +def is_chromeos_garcon(): + """ Return whether we are running in Chrome OS and the browser can't see local files """ + # In Crostini Chrome OS Linux, the default browser opens URLs in Chrome + # running outside the linux VM. This browser does not have access to the + # Linux filesystem. This uses Garcon, see for example + # https://chromium.googlesource.com/chromiumos/platform2/+/master/vm_tools/garcon/#opening-urls + # https://source.chromium.org/search?q=garcon-url-handler + return "garcon-url-handler" in webbrowser.get().name + + # Disable CLI web browsers term = os.environ.pop("TERM", None) # This import must be done with an empty $TERM, otherwise a command-line browser may be started @@ -1549,6 +1559,8 @@ def runThing(): sys.exit(-1) elif is_termux(): subprocess.call(["termux-open-url", url]) + elif is_chromeos_garcon(): + webbrowser.open(url) else: webbrowser.open(fileurl)