I've started to "play around" with PowerShell and am trying to get it to "behave".
One of the things I'd like to do is to customize the PROMPT to be "similar" to what "$M$P$_$+$G" do on MS-Dos:
A quick rundown of what these do:
Character| Description
$m The remote name associated with the current drive letter or the empty string if current drive is not a network drive.
$p Current drive and path
$_ ENTER-LINEFEED
$+ Zero or more plus sign (+) characters depending upon the depth of the pushd directory stack, one character for each level pushed
$g > (greater-than sign)
So the final output is something like:
\\spma1fp1\JARAVJ$ H:\temp
++>
I've been able to add the $M
and $_
functionality (and a nifty History feature) to my prompt as follows:
function prompt
{
## Get the history. Since the history may be either empty,
## a single item or an array, the @() syntax ensures
## that PowerShell treats it as an array
$history = @(get-history)
## If there are any items in the history, find out the
## Id of the final one.
## PowerShell defaults the $lastId variable to '0' if this
## code doesn't execute.
if($history.Count -gt 0)
{
$lastItem = $history[$history.Count - 1]
$lastId = $lastItem.Id
}
## The command that we're currently entering on the prompt
## will be next in the history. Because of that, we'll
## take the last history Id and add one to it.
$nextCommand = $lastId + 1
## Get the current location
$currentDirectory = get-location
## Set the Windows Title to the current location
$host.ui.RawUI.WindowTitle = "PS: " + $currentDirectory
## And create a prompt that shows the command number,
## and current location
"PS:$nextCommand $currentDirectory
>"
}
But the rest is not yet something I've managed to duplicate....
Thanks a lot for the tips that will surely come!
Thanks to EBGReens's answer, my "prompt" is now capable of showing the depth of the stack:
This will get you the count of the locations on the pushd stack:
See if this does what you want:
Thanks to the tips in:
In PowerShell, how can I determine if the current drive is a networked drive or not?
In PowerShell, how can I determine the root of a drive (supposing it's a networked drive)
I've managed to get it working.
My full profile is:
The following will give you the equivalent of $m.