How do I deal with paths when creating a PowerShell alias for a Windows Subsystem for Linux command?Creating...
Why isn't KTEX's runway designation 10/28 instead of 9/27?
Can the harmonic series explain the origin of the major scale?
Calculating the number of days between 2 dates in Excel
The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?
Java - What do constructor type arguments mean when placed *before* the type?
node command while defining a coordinate in TikZ
Simple image editor tool to draw a simple box/rectangle in an existing image
Are taller landing gear bad for aircraft, particulary large airliners?
For airliners, what prevents wing strikes on landing in bad weather?
Would it be legal for a US State to ban exports of a natural resource?
Science Fiction story where a man invents a machine that can help him watch history unfold
Word describing multiple paths to the same abstract outcome
Could solar power be utilized and substitute coal in the 19th century?
How to check participants in at events?
Is there enough fresh water in the world to eradicate the drinking water crisis?
Why is delta-v is the most useful quantity for planning space travel?
What is the term when two people sing in harmony, but they aren't singing the same notes?
What (else) happened July 1st 1858 in London?
Is there an wasy way to program in Tikz something like the one in the image?
How to prevent YouTube from showing already watched videos?
Simulating a probability of 1 of 2^N with less than N random bits
Is exact Kanji stroke length important?
A known event to a history junkie
Books on the History of math research at European universities
How do I deal with paths when creating a PowerShell alias for a Windows Subsystem for Linux command?
Creating a Share with Permissions with Windows PowershellPass quoted argument string to Start-Process in PowerShellAccessing remote server paths with Powershell environment variablesStart-BitsTransfer Works when triggered manually from powershell but not using a windows serviceScheduled task to run a 32-bit PowerShell Script with three argumentsPowershell: invoke-expression with “find”-commandrsync server using Windows Subsystem for LinuxDoes Bash through Linux as a Subsystem for Win10 replace Git Bash for Windows?any way to integrate authentication with subsystem for linux?
I am updating my PowerShell aliases to include utilities from the Windows Subsystem for Linux. For example, I want to launch vim from PowerShell.
Set-Alias -name 'vim' -Value 'Start-Vim'
function Start-Vim {
wsl vim $args
}
This Alias works great if I pass in a simple filename (e.g., vim note.txt
), but it fails if I pass in an absolute file path, a relative path anchored with .
or a relative path with no anchor.
I tried using Resolve-Path to at least get to a single place (a fully resolved path), but that still doesn't work. It launches
vim, but with that path as a new file ("C:tempAPIM Swap.ps1" [New File]
in status line).
I started down the path of replacing strings (replace with
/
), but that only solves relative path with no anchor, and string manipulation doesn't feel like the right solution. Plus, drive letters map to mnts in linux, so I need to deal with that.
Is there a way to convert a file path in Windows to its file path in Windows Subsystem for Linux? Or is there another way to integrate WSL utilities?
powershell windows-subsystem-linux
add a comment |
I am updating my PowerShell aliases to include utilities from the Windows Subsystem for Linux. For example, I want to launch vim from PowerShell.
Set-Alias -name 'vim' -Value 'Start-Vim'
function Start-Vim {
wsl vim $args
}
This Alias works great if I pass in a simple filename (e.g., vim note.txt
), but it fails if I pass in an absolute file path, a relative path anchored with .
or a relative path with no anchor.
I tried using Resolve-Path to at least get to a single place (a fully resolved path), but that still doesn't work. It launches
vim, but with that path as a new file ("C:tempAPIM Swap.ps1" [New File]
in status line).
I started down the path of replacing strings (replace with
/
), but that only solves relative path with no anchor, and string manipulation doesn't feel like the right solution. Plus, drive letters map to mnts in linux, so I need to deal with that.
Is there a way to convert a file path in Windows to its file path in Windows Subsystem for Linux? Or is there another way to integrate WSL utilities?
powershell windows-subsystem-linux
1
I would look atResolve-Path
to address the issue of relative paths.
– EBGreen
May 9 '18 at 18:08
1
I tried that approach, but the resulting resolved path still doesn't appear to be a valid WSL path
– Erick T
May 9 '18 at 18:10
1
Please update your question with what you tried and in what fashion it did not work.
– EBGreen
May 9 '18 at 18:11
AFAIK for it to work properly you must be using relative paths in 1709. Though newer releases (maybe 1803) might have a utilitywslpath
that converts things which you could call in your function/script. github.com/MicrosoftDocs/WSL/releases/tag/17046
– Zoredache
May 10 '18 at 0:41
wslpath seems like exactly what I need. I don't have it in my version yet, but will use that when it comes out
– Erick T
May 10 '18 at 19:43
add a comment |
I am updating my PowerShell aliases to include utilities from the Windows Subsystem for Linux. For example, I want to launch vim from PowerShell.
Set-Alias -name 'vim' -Value 'Start-Vim'
function Start-Vim {
wsl vim $args
}
This Alias works great if I pass in a simple filename (e.g., vim note.txt
), but it fails if I pass in an absolute file path, a relative path anchored with .
or a relative path with no anchor.
I tried using Resolve-Path to at least get to a single place (a fully resolved path), but that still doesn't work. It launches
vim, but with that path as a new file ("C:tempAPIM Swap.ps1" [New File]
in status line).
I started down the path of replacing strings (replace with
/
), but that only solves relative path with no anchor, and string manipulation doesn't feel like the right solution. Plus, drive letters map to mnts in linux, so I need to deal with that.
Is there a way to convert a file path in Windows to its file path in Windows Subsystem for Linux? Or is there another way to integrate WSL utilities?
powershell windows-subsystem-linux
I am updating my PowerShell aliases to include utilities from the Windows Subsystem for Linux. For example, I want to launch vim from PowerShell.
Set-Alias -name 'vim' -Value 'Start-Vim'
function Start-Vim {
wsl vim $args
}
This Alias works great if I pass in a simple filename (e.g., vim note.txt
), but it fails if I pass in an absolute file path, a relative path anchored with .
or a relative path with no anchor.
I tried using Resolve-Path to at least get to a single place (a fully resolved path), but that still doesn't work. It launches
vim, but with that path as a new file ("C:tempAPIM Swap.ps1" [New File]
in status line).
I started down the path of replacing strings (replace with
/
), but that only solves relative path with no anchor, and string manipulation doesn't feel like the right solution. Plus, drive letters map to mnts in linux, so I need to deal with that.
Is there a way to convert a file path in Windows to its file path in Windows Subsystem for Linux? Or is there another way to integrate WSL utilities?
powershell windows-subsystem-linux
powershell windows-subsystem-linux
edited Jul 7 '18 at 12:00
chicks
3,05072033
3,05072033
asked May 9 '18 at 17:59
Erick TErick T
13414
13414
1
I would look atResolve-Path
to address the issue of relative paths.
– EBGreen
May 9 '18 at 18:08
1
I tried that approach, but the resulting resolved path still doesn't appear to be a valid WSL path
– Erick T
May 9 '18 at 18:10
1
Please update your question with what you tried and in what fashion it did not work.
– EBGreen
May 9 '18 at 18:11
AFAIK for it to work properly you must be using relative paths in 1709. Though newer releases (maybe 1803) might have a utilitywslpath
that converts things which you could call in your function/script. github.com/MicrosoftDocs/WSL/releases/tag/17046
– Zoredache
May 10 '18 at 0:41
wslpath seems like exactly what I need. I don't have it in my version yet, but will use that when it comes out
– Erick T
May 10 '18 at 19:43
add a comment |
1
I would look atResolve-Path
to address the issue of relative paths.
– EBGreen
May 9 '18 at 18:08
1
I tried that approach, but the resulting resolved path still doesn't appear to be a valid WSL path
– Erick T
May 9 '18 at 18:10
1
Please update your question with what you tried and in what fashion it did not work.
– EBGreen
May 9 '18 at 18:11
AFAIK for it to work properly you must be using relative paths in 1709. Though newer releases (maybe 1803) might have a utilitywslpath
that converts things which you could call in your function/script. github.com/MicrosoftDocs/WSL/releases/tag/17046
– Zoredache
May 10 '18 at 0:41
wslpath seems like exactly what I need. I don't have it in my version yet, but will use that when it comes out
– Erick T
May 10 '18 at 19:43
1
1
I would look at
Resolve-Path
to address the issue of relative paths.– EBGreen
May 9 '18 at 18:08
I would look at
Resolve-Path
to address the issue of relative paths.– EBGreen
May 9 '18 at 18:08
1
1
I tried that approach, but the resulting resolved path still doesn't appear to be a valid WSL path
– Erick T
May 9 '18 at 18:10
I tried that approach, but the resulting resolved path still doesn't appear to be a valid WSL path
– Erick T
May 9 '18 at 18:10
1
1
Please update your question with what you tried and in what fashion it did not work.
– EBGreen
May 9 '18 at 18:11
Please update your question with what you tried and in what fashion it did not work.
– EBGreen
May 9 '18 at 18:11
AFAIK for it to work properly you must be using relative paths in 1709. Though newer releases (maybe 1803) might have a utility
wslpath
that converts things which you could call in your function/script. github.com/MicrosoftDocs/WSL/releases/tag/17046– Zoredache
May 10 '18 at 0:41
AFAIK for it to work properly you must be using relative paths in 1709. Though newer releases (maybe 1803) might have a utility
wslpath
that converts things which you could call in your function/script. github.com/MicrosoftDocs/WSL/releases/tag/17046– Zoredache
May 10 '18 at 0:41
wslpath seems like exactly what I need. I don't have it in my version yet, but will use that when it comes out
– Erick T
May 10 '18 at 19:43
wslpath seems like exactly what I need. I don't have it in my version yet, but will use that when it comes out
– Erick T
May 10 '18 at 19:43
add a comment |
1 Answer
1
active
oldest
votes
I am able to use the following using Windows 10 Home 177763 and Alpine WSL.
Set-Alias -name 'vi' -Value 'Start-Vi'
function Start-Vi {
wsl vi (Resolve-Path -Relative $args)
}
Note that this will fall over if you don't provide an argument for the function, or if your path is deeper than then working directory.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f911513%2fhow-do-i-deal-with-paths-when-creating-a-powershell-alias-for-a-windows-subsyste%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am able to use the following using Windows 10 Home 177763 and Alpine WSL.
Set-Alias -name 'vi' -Value 'Start-Vi'
function Start-Vi {
wsl vi (Resolve-Path -Relative $args)
}
Note that this will fall over if you don't provide an argument for the function, or if your path is deeper than then working directory.
New contributor
add a comment |
I am able to use the following using Windows 10 Home 177763 and Alpine WSL.
Set-Alias -name 'vi' -Value 'Start-Vi'
function Start-Vi {
wsl vi (Resolve-Path -Relative $args)
}
Note that this will fall over if you don't provide an argument for the function, or if your path is deeper than then working directory.
New contributor
add a comment |
I am able to use the following using Windows 10 Home 177763 and Alpine WSL.
Set-Alias -name 'vi' -Value 'Start-Vi'
function Start-Vi {
wsl vi (Resolve-Path -Relative $args)
}
Note that this will fall over if you don't provide an argument for the function, or if your path is deeper than then working directory.
New contributor
I am able to use the following using Windows 10 Home 177763 and Alpine WSL.
Set-Alias -name 'vi' -Value 'Start-Vi'
function Start-Vi {
wsl vi (Resolve-Path -Relative $args)
}
Note that this will fall over if you don't provide an argument for the function, or if your path is deeper than then working directory.
New contributor
New contributor
answered 7 mins ago
Matthew BegunMatthew Begun
1
1
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f911513%2fhow-do-i-deal-with-paths-when-creating-a-powershell-alias-for-a-windows-subsyste%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I would look at
Resolve-Path
to address the issue of relative paths.– EBGreen
May 9 '18 at 18:08
1
I tried that approach, but the resulting resolved path still doesn't appear to be a valid WSL path
– Erick T
May 9 '18 at 18:10
1
Please update your question with what you tried and in what fashion it did not work.
– EBGreen
May 9 '18 at 18:11
AFAIK for it to work properly you must be using relative paths in 1709. Though newer releases (maybe 1803) might have a utility
wslpath
that converts things which you could call in your function/script. github.com/MicrosoftDocs/WSL/releases/tag/17046– Zoredache
May 10 '18 at 0:41
wslpath seems like exactly what I need. I don't have it in my version yet, but will use that when it comes out
– Erick T
May 10 '18 at 19:43