mskyaxl / wsl-terminal

Terminal emulator for Windows Subsystem for Linux (WSL)
MIT License
3.12k stars 159 forks source link

How to make wstart use linux path #62

Closed alankritjoshi closed 6 years ago

alankritjoshi commented 6 years ago

I want to use cmdtool wstart $filename where $filename represents the relative/absolute linux path of file in pwd. However, it seems to want the absolute Windows path of the file. How do I make it work like I want to? I can only think of making a bash function to handle that.

goreliu commented 6 years ago

I added a wstartex subcommand https://github.com/goreliu/wsl-terminal/commit/fd9ca6c833746b9f82d437a7f1c641b593da6dfd

Examples:

# Open ./etc/themes directory with explorer.exe
$ ./cmdtool wstartex etc/themes

# Open /mnt/c/Windows/win.ini with notepad.exe
$ ./cmdtool wstartex /mnt/c/Windows/win.ini

# Open www.google.com with the default browser
$ ./cmdtool wstartex www.google.com

Or use a standlone wstart script:

#!/bin/bash

wstart_run='setsid /init /mnt/c/Windows/System32/cmd.exe /c start'

if [[ "$1" == http* || "$1" == www* ]]; then
    exec $wstart_run "" "$@"
fi

dir_name="$(dirname $1)"
file_name="$(basename $1)"

if [[ "$dir_name" == / ]]; then
    cd /; $wstart_run .; cd - >/dev/null
elif [[ "$dir_name" == /mnt ]]; then
    cd /; $wstart_run "" "$file_name":; cd - >/dev/null
else
    shift 2>/dev/null
    cd "$dir_name" && $wstart_run "" "$file_name" "$@"; cd - >/dev/null
fi 
alankritjoshi commented 6 years ago

@goreliu awesome! Thank you for this feature. Ability to open websites is a neat touch!

Can we see this in the next release so that ./cmdtool update works?

goreliu commented 6 years ago

Yes, I released v0.8.7 just now.

alankritjoshi commented 6 years ago

@goreliu that was fast! Thanks! It works except for relative paths or when the absolute path has spaces in them.

For example,

cmdtool wstartex . cmdtool wstartex /mnt/d/files/a\ directory\ with\ space/a\ file\ with\ space.py

I can manage this in my zsh though but as an inbuilt feature of wstartex would be great.

goreliu commented 6 years ago

I will fix it, and I am using this zsh script, it works.

#!/bin/zsh

alias run='setsid /init /mnt/c/Windows/System32/cmd.exe /c start'

if [[ $1 == http* || $1 == www* ]] {
    run "" $*
    return
}

dir_name=${1:h}
file_name=${1:t}

if [[ $dir_name == / ]] {
    cd /; run .; cd - >/dev/null
} elif [[ $dir_name == /mnt ]] {
    cd /; run "" $file_name:; cd - >/dev/null
} else {
    shift 2>/dev/null
    cd $dir_name && run "" $file_name $*; cd - >/dev/null
}
alankritjoshi commented 6 years ago

@goreliu thanks for the fix. It solves my issue :)

goreliu commented 6 years ago

I fixed it (https://github.com/goreliu/wsl-terminal/commit/234e3bb3a99c73bfefb0f8ed57889dffb8229a41).

alankritjoshi commented 6 years ago

@goreliu Great! Will pull from the next release

alankritjoshi commented 6 years ago

@goreliu did the last change make it into the release?