LoginSignup
2
0

More than 3 years have passed since last update.

fish_configでブラウザが起動しない

Last updated at Posted at 2018-12-09

fish_configでブラウザが起動しない

zshからfish shellに乗り換えたのですが、fish_configで設定しようとしたら、ブラウザが起動せず、Visual Studio Codeが起動して困っていました。そこで調べたことをメモしました。

環境

OS Version
Ubuntu 18.04

fish_configの調査

最初にfish_configを調べました。fish_configの設定画面にあるfunctionsからfish_config関数の中身を確認しました。

# Defined in /usr/share/fish/functions/fish_config.fish @ line 1
function fish_config --description Launch\ fish\'s\ web\ based\ configuration
  set -lx __fish_bin_dir $__fish_bin_dir
  if command -sq python3
    python3 "$__fish_datadir/tools/web_config/webconfig.py" $argv
  else if command -sq python2
    python2 "$__fish_datadir/tools/web_config/webconfig.py" $argv
  else if command -sq python
    python "$__fish_datadir/tools/web_config/webconfig.py" $argv
  end
end

fish_configを実行するとPythonのソースが呼び出されていました。ソースの場所を調べたら、/usr/share/fish/tools/web_config/webconfig.pyにソースがありました。

webconfig.pyの調査

webconfig.pyのソースの中身を確認して、ブラウザを起動している箇所を調べました。

import webbrowser

# Open temporary file as URL
# Use open on macOS >= 10.12.5 to work around #4035.
fileurl = 'file://' + filename
print("Web config started at '%s'. Hit enter to stop." % fileurl)
if isMacOS10_12_5_OrLater():
    subprocess.check_call(['open', fileurl])
else:
    webbrowser.open(fileurl)

ブラウザを起動している箇所はwebbrowser.open(fileurl)で、importしているwebbrowserライブラリを調べました。

webbrowserの調査

webbrowserライブラリからデフォルトで起動しているアプリケーションを調べるために、以下のプログラムを作成して、実行しました。

import webbrowser

controller = webbrowser.get()

print(controller.__class__.__name__)
print(controller.name)

実行結果

BackgroundBrowser
xdg-open

ブラウザのコントローラーオブジェクトの名前からxdg-openコマンドでブラウザを起動していることがわかりました。

xdg-openの設定

xdg-openコマンドで起動するmimeタイプtext/htmlのデフォルトアプリケーションを取得します。

> xdg-mime query default text/html
code-url-handler.desktop

mimeタイプの設定は/usr/share/applicationsにあり、text/htmlのデフォルトアプリケーションはcode-url-handler.desktopが設定されていました。code-url-handler.desktopを開くとVisual Studio Codeが起動する設定になっていました。これが原因でした。

[Desktop Entry]
Name=Visual Studio Code - URL Handler
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/share/code/code --open-url %U
Icon=code
Type=Application
NoDisplay=true
StartupNotify=true
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=x-scheme-handler/vscode;
Keywords=vscode;
X-Desktop-File-Install-Version=0.23

text/htmlのデフォルトアプリケーションにChromiumを設定します。

xdg-mime default chromium-browser.desktop text/html

これでfish_configでブラウザが起動するようになりました。

参考文献

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0