Custom Directory Path in PowerShell Prompt
Tired of Long unwanted directory paths in PowerShell Prompt in the console? Well I’m! Totally tired of looking long directory paths because I spent most of the my time working on PowerShell terminals
THE PROBLEM – Long Paths PowerShell Prompt :
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.
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.
HOW TO MAKE IT WORK :
- Go to your Powershell terminal and type “ISE $Profile” to open the Powershell $Profile in ISE.
- Copy-Paste the script from the Script category from this blog post (above) to your $Profile, like below
- Make the necessary changes in the
$CustomDirectoriesHashtable, which would be specific to your requirement.
- Save the Profile.
- Close and reopen ISE in order to make the changes get reflected
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!
My new book : PowerShell Scripting Guide to Python
This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time.
“Use what you know to learn what you don’t. ” also known as Associative learning.
Book follows a comparative method to jump start readers journey in Python, but who is the target audience? and who should read this book –
- Any System Administrator who want to step into Development or Programming roles, and even if you don’t want to be a developer, knowledge of another scripting language will make your skill set more robust.
- Python Developers who want to learn PowerShell scripting and understand its ease of user and importance to manage any platform.
Python is one of the top programming languages and in fast changing IT scenarios to DevOps and Cloud to the future – Data Science, Artificial Intelligence (AI) and Machine Learning Python is a must know.
But this PowerShell Scripting guide to Python would be very helpful for you if you already have some knowledge of PowerShell
NOTE! This is a Leanpub “Agile-published” book. That means the book is currently unfinished and in-progress. As I continue to complete the chapters, we will re-publish the book with the new and updated content. Readers will receive an email once a new version is published!
While the book is in progress, please review it and send any feedback or error corrections at [email protected]