Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an alias to quickly navigate to a folder

Tags:

powershell

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)

New-Item alias:foo -value c:\repos\my\code\here

... 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.

like image 907
Jim Aho Avatar asked Nov 30 '22 15:11

Jim Aho


1 Answers

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

$repos = @{
    angular = 'c:\repos\my\angular\here'
    typescript = 'c:\repos\my\typescript\here'
    csharp = 'c:\repos\my\csharp\here'
}

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

cd $repos.angular

And even use tab-completion!

like image 73
Martin Brandl Avatar answered Jan 08 '23 05:01

Martin Brandl