I would like to shorten my PowerShell prompt so that it just shows the parent directory and the current directory. For example, if the pwd is
C:\Users\ndunn\OneDrive\Documents\Webucator\ClassFiles\python-basics\Demos
I want the prompt to be:
PS ..\python-basics\Demos>
I can get it to be just PS ..\Demos> by changing the prompt() function in the Profile file:
- Find location of Profile file by running
$profilein PowerShell. - Open (or create and open) Profile file.
- Change (or add) the following
prompt()function:
function prompt
{
$folder = "$( ( get-item $pwd ).Name )"
"PS ..\$folder> "
}
I tried using split() and negative indexing, but wasn't able to get it to work.
Also, I only want to do this if the pwd is at least two levels down. If the pwd is something like C:\folder\folder, I'd like to show the default prompt.
Any ideas?
