Tired of Long unwanted directory paths in Powershell terminal? Well I’m! Totally tired of looking long directory paths because I spent most of the my time working on Powershell terminals

THE PROBLEM :

When Dealing with long directory paths, we are literally typing on right hand side of your powershell console, moreover console starts wrapping the text when your command hits the edge of the terminal making it even worse to read, like in the below image.

SOLUTION :

There has to be a smarter way, through which we can make custom paths (Aliases) of the Directory names. To achieve this, I’ve quick tip to fix this Using a Hash Table – To Map Directory name to their respective Custom Names like in following Image

and a small Powershell Function to return Custom directory names on basis of above HashTable, which is much shorter in Length.

In short, the function fetch the $PWD (Present Working Directory) and returns the possible alias (If any) defined by you in the HashTable. Following animation demonstrates few examples.

SCRIPT :

HOW TO MAKE IT WORK :

Go to your Powershell terminal and type “ ISE $Profile ” to open the Powershell $Profile in ISE. ISE $Profile Copy-Paste the script from the Script category from this blog post (above) to your $Profile , like below Make the necessary changes in the $CustomDirectories Hashtable , which would be specific to your requirement . Save the Profile. Close and reopen ISE in order to make the changes get reflected

NOTE :

Obviously you’ve a choice to Either Remove the Directory Path from Prompt function or to move it to the Powershell Host Title using below Property.

$Host.UI.RawUI.WindowTitle = $PWD.Path

But my solution was for when you want to live with Directory path in the Powershell console 🙂

Hoping you’ll find useful, have nice day!

Prateek Singh

Follow @SinghPrateik