LoginSignup
8
4

More than 1 year has passed since last update.

WSLからファイルをWindows側のブラウザで開く (cargo doc --openする)

Last updated at Posted at 2021-03-05

#動機
wslでcargo doc --openしたときにブラウザで開くようにしたかった。

#試行錯誤

ここからBROWSER環境変数にいれてやればいいとわかる。

wslって.exe開けるのを初めて知った。これで./bashrcを書き換えて終わり..ではなかった。
firefoxは起動するが、対象のページを開いてくれなかった。これは、firefoxに送られるpathがlinux側のものなのでwindows用に変換しなければならない。ただ頭にubuntuの場合はfile://///wsl$//Ubuntuを足せばいい。BROWSER環境変数にshellファイルを入れてそれを経由して呼び出した。

#やり方

open_browser.sh
#! /bin/bash
#firefox
/mnt/c/Program\ Files/Mozilla\ Firefox/firefox.exe $(wslpath -w ${1})
#chrome
#/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe $(wslpath -w ${1})
~/.bashrc
# xxxにshellスクリプトのディレクトリを入れる
export BROWSER='xxx/open_browser.sh'

これでwslからcargo doc --openしたときにブラウザでdocが開くようになった。
chromeの場合開いている間cargo docが終わらないのが少し気になったが…
最初からブラウザを開いていると終わってくれるようだ

追記1

wslpathコマンドというものがあるようなので修正
ブラウザが閉じないことに対する追記

追記2

いつの間にかcargo docでは解消されていた。
https://github.com/rust-lang/cargo/issues/7557

8
4
0

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
8
4