0
0

More than 1 year has passed since last update.

wslでopen

Last updated at Posted at 2020-10-12

イントロ

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 ruby
require 'open3'

target = ARGV[0] || '.'
case 
when target == '.'
  out, err, status = Open3.capture3("explorer.exe .")
when target.match(/^http/)
  system "cmd.exe /c start #{target}"
else
  puts "no command for #{target}"
end

追記

  • 同じ用途に,xdg-open がUbuntuでは使えるらしい.

wslで確認が必要.


  • source ~/git_hub/ruby_docs/multi_scale_22_text/excludes/semi_lattice_20f/open_script_onWSL/wsl_open.org
0
0
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
0
0