In Cygwin I can drag and drop a windows file or folder and
have its path updated to linuxy version.
In WSL they do not have this feature yet.
So…
In WSL you do have a path to local drives. It is at /mnt
I can do something like this
|
> ls /mnt/d/pictures/ |
And that works.
But if I drag and drop the D:\pictures folder into Ubuntu WSL I get…
D:\pictures
Which is not a converted linuxy path like Cygwin does.
So its not going to work as is.
However there is a tool
wslpath
we can use to convert it. Its not as convenient but it works
Let’s say we want to change directory
Type in this first part of the command
|
> cd $(wslpath " |
Then drag and drop in the folder and add in a ") to close it
That works…
but it’s a bit of a pain.
I would rather have some kind of automation.
here is the best I came up with, replacing the cd command.
This still requires you to put the win path in quotes because linux will ignore
the single \ in the path
Update .bashrc
|
> vi ~/.bashrc |
And add this to the bottom
|
cd() { if [ $# -eq 1 ] && [[
"$1" =~ ^[a-zA-Z]:\\ || "$1" =~ ^[a-zA-Z]:/ ||
"$1" =~ ^\\\\ ]]; then local linuxpath if [ $? -eq 0 ] && [ -d
"$linuxpath" ]; then |
Now I can either restart my terminal or run
|
> source ~/.bashrc |
To pick up the changes
Now let me try it
|
> cd "D:\pictures" |
That works!
No comments:
Post a Comment