20 Apr, 2023
I work in the terminal quite a bit, and needed a quick way to change directories between projects. I started this based off a similar project in bash called lazy-cd. This works similarly as it stores the bookmarks you add to a file, and if the bookmark is found, the terminal location will be set accordingly.
Making this work, I knew a few functions were needed and was interested in some better function management. I learned a lot on processes, procedures, function arguments, and some simple regex to help search and find the bookmark item for each function and cleanly execute the task at hand.
Check-Bookmark- Initializing function to create bookmark file if needed
View-Bookmark- List all the bookmarks that have been added to the library
Add-Bookmark <name>- Adds the bookmark using the
<name>and the current location you are in
Delete-Bookmark <name>- Remove the specified bookmark line based on the
Goto-Bookmark <name>- If the bookmark
<name>exists in the bookmark file, the terminal will
Set-Locationto the path defined.
Download the the
bookmark.ps1 file and dot source it to your
. "path\to\bookmarks.ps1" PS C:> bmv You have 4 Bookmarks Bookmark Path -------- ---- home C:\Users\username website C:\git\cjerrington.github.io snippets C:\git\snippets root C:\
You can view the source code and help improve the process if needed as well. Check out the Bookmark repo on Codeberg. Oh, and to be exciting, it's less than 100 lines of code!
I was chatting on mastodon the other day and got some great advice as well from a few folks on how to make this possible.
Thanks to the following for some inspiration!
If there are replies, they will show below.