Created
May 30, 2017 13:00
-
-
Save shmuelie/24f8af8372af7312bbff230cd4ca8ff2 to your computer and use it in GitHub Desktop.
PowerShell Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-OneDriveFolder | |
{ | |
<# | |
.Synopsis | |
Gets the current user's OneDrive folder. | |
.Description | |
Gets the current user's OneDrive folder. | |
.Example | |
cd (Get-OneDriveFolder) | |
C:\Users\Admin\OneDrive | |
Description | |
----------- | |
Returns the location of the current user's OneDrive folder. | |
.Outputs | |
System.String | |
#> | |
[CmdletBinding()] | |
param() | |
process | |
{ | |
(Get-ItemProperty -Path "hkcu:\Software\Microsoft\OneDrive\" -Name UserFolder).UserFolder | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Invoke-Nano | |
{ | |
<# | |
.Synopsis | |
Start nano | |
.Description | |
Start nano in WSL | |
.Parameter File | |
Path to the file to edit. Can be relative or absolute. If not given starts with empty new file. | |
.Example | |
Invoke-Nano -File C:\Windows\WindowsUpdate.log | |
Description | |
----------- | |
Starts nano editing the C:\Windows\WindowsUpdate.log file | |
.Inputs | |
System.String | |
.Notes | |
The path will be automatically converted to the correct path for WSL. | |
.Link | |
https://linux.die.net/man/1/nano | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$False,Position=1,ValueFromPipeline=$True)] | |
[string]$File | |
) | |
process | |
{ | |
if ([System.String]::IsNullOrWhiteSpace($File)) | |
{ | |
bash -c nano | |
return | |
} | |
if ((Test-Path -Path $File) -eq $False) | |
{ | |
[System.String]::Empty | Set-Content -Path $File | |
} | |
$FullPath = Resolve-Path -Path $File | |
Write-Verbose "Opening file $FullPath" | |
$Root = $FullPath.Drive.Root | |
$Drive = $FullPath.Drive.Name.ToLowerInvariant() | |
$Path = $FullPath.Path.Remove(0, 3) | |
$NixPath = $Path.Replace("\", "/") | |
$NixFullPath = "/mnt/$Drive/$NixPath" | |
Write-Verbose "*nix path $NixFullPath" | |
bash -c "nano '$NixFullPath'" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment