Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make help and fish_config work on Chrome OS #7789

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 10 additions & 2 deletions share/functions/help.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
42 changes: 27 additions & 15 deletions share/tools/web_config/webconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
COMMON_WSL_CMD_PATHS = (
"/mnt/c/Windows/System32",
"/windir/c/Windows/System32",
"/c/Windows/System32"
"/c/Windows/System32",
)
FISH_BIN_PATH = False # will be set later
IS_PY2 = sys.version_info[0] == 2
Expand All @@ -37,6 +37,21 @@
import socketserver as SocketServer
from urllib.parse import parse_qs

try:
import json
except ImportError:
import simplejson as json


# 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
# which will block the whole process - see https://docs.python.org/3/library/webbrowser.html
import webbrowser

if term:
os.environ["TERM"] = term


def find_executable(exe, paths=()):
final_path = os.environ["PATH"].split(os.pathsep)
Expand Down Expand Up @@ -71,19 +86,14 @@ def is_termux():
return "com.termux" in os.environ["PATH"] and find_executable("termux-open-url")


# 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
# which will block the whole process - see https://docs.python.org/3/library/webbrowser.html
import webbrowser

if term:
os.environ["TERM"] = term

try:
import json
except ImportError:
import simplejson as json
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


def run_fish_cmd(text):
Expand Down Expand Up @@ -982,7 +992,7 @@ def do_get_variables(self):
vars[name].exported = True

# Do not return history as a variable, it may be so large the browser hangs.
vars.pop('history', None)
vars.pop("history", None)

return [
vars[key].get_json_obj()
Expand Down Expand Up @@ -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)

Expand Down