-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Location history for use with Push-Location and Pop-Location can be kept in separate history stacks, if desired.
These stacks cannot be managed directly; they are indirectly managed via the *-Location cmdlets.
- You indirectly create a stack with
Push-Location -StackName <name>. - Once created, further locations can be pushed and popped.
Set-Location -StackName <name>can be used to make a given stack the current stack.Get-Location -Stack [-StackName <name>]returns the locations currently stored in the active / given stack.
However, there is currently no way to clear a stack (other than by popping off all items through repeated Pop-Location calls).
Clearing a stack is desirable if you want to make sure that it is empty before you use it - either to reuse a previously used stack or in cases where previously executed code may have created a stack by the same name.
Secondarily,
-
there's also no way to delete a stack, although, arguably, the ability to clear stacks is enough.
-
there's no test whether a stack with a given name exists, other than letting
Get-Location -StackName <name>fail; arguably, rather than worrying about explicit existence / deletion of stacks, lettingGet-Location -Stack -StackName <name>return nothing (the null collection) for a nonexistent stack is preferable, given thatGet-Location -Stackwith the unnamed stack already works that way.
As an aside: While calling the .Clear() method on the stack object that Get-Location -Stack returns may seem like a workaround for the current inability to clear a stack using cmdlets, it doesn't actually work (only clears the object returned, not the actual stack); more importantly, Get-Location -Stack should arguably return an array of location paths rather than a scalar stack
object - see ##4642.
Environment data
PowerShell Core v6.0.0-beta.5