Last active
October 10, 2019 14:37
-
-
Save exlted/0f09d538f494ab9faf44e414965dd6b8 to your computer and use it in GitHub Desktop.
Jump-Location
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
using module Simple-Settings | |
$storageLoc = Join-Path $PSScriptRoot "jumpConf.xml" | |
$global:Storage = New-Object SettingsObj -ArgumentList $storageLoc | |
New-Alias Jump-Location Move-Location | |
New-Alias Move-Shortcut Move-Location | |
New-Alias Jump-Shortcut Move-Location | |
function Move-Location { | |
$location = Get-Jump @args | |
cd $location | |
} | |
New-Alias Get-Shortcut Get-Jump | |
function Get-Jump { | |
if($args.Count -lt 1){ | |
Write-Error "Requires at least 1 parameter to be passed in" | |
return "" | |
} | |
$key = "" | |
$countInKey = 0; | |
foreach($arg in $args){ | |
if($key -eq ""){ | |
$tempKey = $arg.ToString(); | |
} else { | |
$tempKey = $key + '|' + $arg.ToString() | |
} | |
if($global:Storage.hasSetting($tempKey)){ | |
$key = $tempKey | |
$countInKey += 1 | |
} else { | |
if($key -eq ""){ | |
Write-Error "Could not find $args[0] in jump dictionary" | |
return "" | |
} else { | |
break; | |
} | |
} | |
} | |
$rv = $global:Storage.getSetting($key) | |
for($i = $countInKey; $i -lt $args.Count; $i++){ | |
$rv = Join-Path -Path $rv -ChildPath $args[$i].ToString() | |
} | |
return $rv | |
} | |
function Get-Jumps { | |
$global:Storage.printSettings() | |
} | |
New-Alias Add-Shortcut Add-Jump | |
function Add-Jump { | |
param( | |
[string]$shortcut, | |
[string]$location | |
) | |
$global:Storage.setSetting($shortcut, $location); | |
} | |
New-Alias Load-Shortcuts Import-Jumps | |
New-Alias Load-Jumps Import-Jumps | |
New-Alias Import-Shortcuts Import-Jumps | |
function Import-Jumps { | |
$global:Storage.updateSettings(); | |
} | |
New-Alias Remove-Shortcut Remove-Jump | |
function Remove-Jump { | |
param( | |
[string]$shortcut | |
) | |
$global:Storage.updateSettings(); | |
$global:Storage.RemoveSetting($shortcut); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to utilize my new Simple-Settings persistent settings module