イントロ
wslでもmacみたくopenを使いたい.
実装(bash)
bashでのopenです..bashrcに追加して読み込むようにしています.
open(){local browser='/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe'for arg;do
if[-e"${arg}"];then
readlink-f${arg} |xargs wslpath -w |powershell.exe start
elif[[${arg}=~ http ]];then
echo"${arg}" | xargs "${browser}"fi
done}
実装(ruby)
rubyでの実装です.ほんとうはfishのfunctionにしたかったのですが,あんまり情報なくて.しかたがないので,~/bin/openとして置いて,これをfishのPATHに入れてうごかしています.openというのがubuntuの/sbinにあるようですが,それとは違うようです.
#!/usr/bin/env rubyrequire'open3'target=ARGV[0]||'.'casewhentarget=='.'out,err,status=Open3.capture3("explorer.exe .")whentarget.match(/^http/)system"cmd.exe /c start #{target}"elseputs"no command for #{target}"end
- source ~/Desktop/lecture_20f/semi_lattice/bash_script/wsl_open.org