Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function List-Stack {
- $index = 0;
- $locations = (Get-Location -Stack).ToArray()
- foreach($location in $locations)
- {
- Write-Host $index $location.Path
- $index++
- }
- }
- function Set-NewLocation($index) {
- $location = (Get-Location -Stack).ToArray() | select -Index $index
- Set-Location -Path $location
- }
- function Clear-Stack {
- $locations = (Get-Location -Stack).ToArray()
- foreach($location in $locations)
- {
- Pop-Location
- }
- }
- # Aliases for less typing, change as you see fit
- Set-Alias -name 'cwd' -value 'Push-Location'
- Set-Alias -name 'cds' -value 'Set-NewLocation'
- Set-Alias -name 'cdl' -value 'List-Stack'
- Clear-Stack
- cwd c:\Windows\System32
- cwd c:\Windows
- cwd c:\Temp
- # This will not be in the stack unless we cwd somewhere else
- cwd c:\Users
- cdl
- cds 2
- <# Output:
- PS C:\users\Chris> C:\Users\Chris\Documents\dirtest.ps1
- 0 C:\Temp
- 1 C:\Windows
- 2 C:\Windows\System32
- 3 C:\users\Chris
- PS C:\Windows\System32>
- #>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement