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.
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!
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 prateek@ridicurious.com
Prateek Singh
Related posts
0 Comments
Leave a Reply to Prateek SinghCancel reply
Categories
Author of Books
Awards
Open Sourced Projects
Author at
Blog Roll
Mike F RobbinsDamien Van Robaeys
Stéphane van Gulick
Kevin Marquette
Adam Bertram
Stephanos Constantinou
Francois-Xavier Cat
Ravikanth Chaganti
Roman Levchenko
Blog Stats
- 1,133,280 People Reached
[…] on October 18, 2016 submitted by /u/Prateeksingh1590 [link] [comments] Leave a […]
My cheap take was… I added an ending “CRLF” (back tick r, back tick n) to the prompt.
I got used to seeing my cmd line “below” the looooong path.
$0.02
🙂 Marcelo
VMware Certified Advanced Professional 6 (Desktop and Mobility Deployment) – The industry-recognized VCAP6-DTM Deploy certification validates that you know how to deploy and optimize VMware Horizon 6 (with View) environments. It demonstrates that you have the understanding and skills essential to leverage best practices to provide a scalable and reliable Business Mobility platform for your business. Some of the subject areas include: Configuring and managing Horizon View components, configuring cloud pod archituecture, configuring Group Policy settings related to Horizon View, Configuring and optimizing desktop images for Horizon View & Mirage, Configuring and managing App Volumes AppStacks, Configuring desktop pools, Configuring and deploying ThinApp packaged applications, Configuring VMWare Identity Manager, etc.Sebastian’s take on the VCAP6 examination: “In my viewpoint VCAP6 exam is way better experience when compared with VCAP5, the newest exam appears to be just like VMware HOL. The screen isn’t hard, questions are prepared on the right side of the display, and could be hidden to the side or even restored when desired. My bits of advice to the questions windowpane: if you want to make it floating, you must know how to restore it back. I ended up shifting it around simply because I forget about how to recover it back. The two arrows that looked like buttons on top were intended to dock the window to right or left. Fonts can be resized, which i think was much better than scrolling up and down the question. The response speed of the entire interface was so noticeably faster in comparison with VCAP5.5, and there was no lagging period experienced when transitioning from window to window. One thing to bear in mind: BACKSPACE key is not working! I do believe it is good as you don’t reload your exam window in error, nevertheless, it could be frustrating at times when you type something erroneously and you have to select and press Del to remove. The Desktop and shortcuts were sorted properly, and needed applications like browser or Mirage console could be launched. There’s a excellent interface for Remote Desktop Manager where you can find all necessary RDP connection to servers or desktops without the need to type username and password. The web browser had all the links in the Favorite Bar. Right at that moment I’m writing this, there is no additional Thirty minute extension for Non-Native English speaker at No-Native English country, which is a bummer. There are 39 question to respond within the 3 hours time, which can be actually quite hard for non-native English speakers just like me. Several questions take time to complete, making it wise to neglect the questions that you can’t answer, and finish those you are able to. After the thirty-nine questions, you could visit the uncompleted questions should you have time. Don’t waste too much time on one single question! The exam blue print is found on my blog site at Szumigalski.com. It is well organized and following it for the exam preparation can help a great deal. Obviously, the best is if you can have lots of practical experience! I’m truly very pleased with the exam experience, although I passed this time by small margin, however i really know what I missed for the exam, study from the mistakes and practice harder to familiarise myself with the environment. This credentials is going to open up your career prospects!”
Nice post – just discovered your blog and I’m tweaking my environment due to your tips.
I add the current time to my prompt too (where you have the “I heart PS”) so that my transcripts, screenshots etc have the time I was working on a script. That way it gives me a rough idea of how long a command took (assuming that I started to type immediately after the prompt returned instead of 5 minutes later! Very useful when entering data into my timesheet.
My first line in the prompt function reads as follows:-
Write-Host $((Date -uformat %T).ToString()) -NoNewline
Cool, have fun! 🙂