Created
June 29, 2021 09:12
-
-
Save tkapin/9c579705f74d84728de5dc57998d8f5c to your computer and use it in GitHub Desktop.
PowerShell Mark Recall
This file contains hidden or 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
# Include in your $profile to allow easy directory bookmarking and navigation | |
Function Get-MarksFilePath {return "$env:USERPROFILE\marks.xml"} | |
Function Get-DefaultMarkName {return "(default)"} | |
Function Get-Marks { | |
try { | |
return Import-CliXML (Get-MarksFilePath) | |
} | |
catch [System.IO.FileNotFoundException] { | |
return @{} | |
} | |
} | |
Function Set-Marks { | |
param($marks) | |
Export-Clixml -Path (Get-MarksFilePath) -InputObject $marks | |
} | |
Function Set-Mark { | |
param([string] $alias = (Get-DefaultMarkName)) | |
$marks = Get-Marks | |
$marks[$alias] = $(Get-Location).Path | |
Set-Marks $marks | |
} | |
Function Open-Mark { | |
param([string] $alias = (Get-DefaultMarkName)) | |
$marks = Get-Marks | |
$location = $marks[$alias] | |
if ($location) { | |
Set-Location $location | |
} else { | |
Write-Error "Undefined location '$alias', use Get-Marks to get list of defined locations" | |
} | |
} | |
# aliases | |
Set-Alias -Name m -Value Set-Mark | |
Set-Alias -Name r -Value Open-Mark | |
Set-Alias -Name l -Value Get-Marks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment