PowerShell Location Bookmark for Easy and Faster Navigation
I work at the command line most of the time and sometimes I find moving to certain folders very tedious and requires lot of typing (even with tab-completion). For example, one of the locations (may not be very frequent) that I move to when working at PowerShell console or ISE is my local GitHub folder where all my repositories are stored. Another example could be the configuration folder in C:\Windows\System32. At times, this is frustrating. So, I wanted something simple but useful for me to just type as few characters as possible but still let me navigate to the place I want to.
So, this is when I started writing out something quick and added a few functions to my Profile script. And, then I tweeted that! 🙂
Location bookmarks in #PowerShell! pic.twitter.com/je278bAWy4
— @ravikanth@hachyderm.io (@ravikanth) May 5, 2016
I saw a few suggestions as a response to this.
PSDrives
One suggestion was to use the New-PSDrive cmdlet and add one for each location I want to quickly move to. This is not very intuitive to me. I can map something like Conf: to go to C:\Windows\System32\Configuration but I don’t get tab-completion. I always have to type the full drive name like cd conf:. You can tab-complete within the drive but not the drive itself.
Jump.Location or ZLocation modules
These modules are very good. It learns your usage and then auto-completes the path based on the history! This is good if you are frequently accessing a few folders. However, this is not my case, exactly. I wanted an easier way to navigate to a longer path and of course, at the same time make it easy for me to get into some of the folders that I use frequently.
So, here it is: PSBookmark!
PSBookmark
This module is a very simple module that provides four commands to manage location bookmarks in PowerShell. This has been very useful for me and while I don’t see me investing lot of time in this, I will certainly implement any feedback or suggestions you may have.
How do you get this?
Simple! Either clone my Github repo or get it from PowerShell Gallery!
|
|
How to use this?
Since the idea is to make it easy to navigate and avoid lot of typing, I will use aliases instead of the full function names. I had a hard time coming up with the function names but aliases were very easy.
|
|
Create a New Location Alias
You can use the save command to save alias for either the PWD or a specific path.
|
|
Jump or Goto a Saved Location Alias
|
|
Get All Saved Alias Locations
|
|
Remove a Saved Alias Location
|
|
TODO
- This was written in just a few minutes and did not spend any time polishing it. So, there is certainly scope for improvement.
- At the moment, the aliases are stored as a hash table in a .PS1 file in $env:UserProfile. This may change in future.