Create an alias to quickly navigate to a folder

Question:

I want to include something in my PowerShell profile loading script that makes it very easy for me to navigate across different folders (different code repositories).

I’ve seen examples that uses New-PSDrive but I thought aliases is a smoother way of doing it. Aliases just feels better.

I’m looking for something like this:

(In profile.ps1)

… Later on in the in the powershell console …:

cd $foo

And voila! I’m now standing in the c:\repos\my\code\here directory.

What’s the right approach?

EDIT: I’ve marked Martins answer as accecpted as its very straight to the point, however I recommend you also read Matt’s answer, it has some great points.

Answer:

I would create a $repos hashtable containing all your repositories:

Put this in your $profile and you can change the directories like this:

And even use tab-completion!

Source:

Create an alias to quickly navigate to a folder by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply