I would like to display the last command that i have entered into powershell in the title of the window so that it is easier to find
Currently I have:
C:\> $host.ui.rawui.WindowTitle = $$
but this just gets the previous command relative to when i enter it so if I have
C:\> cd
C:\> $host.ui.rawui.WindowTitle = $$
the title stays cd
instead of changing with every command i give it.
Is there a way I can set the title so it changes with every command I enter, ie
entering
C:\> cd
will change it to cd
and then
C:\> python
will change it to python
?
You can use your custom function prompt
defined in your profile.
For example:
function prompt {
# get the last command from history
$command = Get-History -Count 1
# set it to the window title
if ($command) {
$host.ui.rawui.WindowTitle = $command
}
# specify your custom prompt, e.g. the default PowerShell:
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
}
Note: use of $^
and $$
in this function does not help, they are not yet set to the last command data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With