Since I’ve been quarantined at home and working in my office, every day is the same. I can’t go to the gym, or coach, or go to the restaurant, or much of anything. As a result, I regularly, forget what day it is.
Yes, it’s on my phone, but that’s not always open and visible. It’s on my watch, but I have to swing up my wrist and hope it lights up. Or reorient my wrist to see it.
I have Rainmeter running, which is nice, and I have a summary in the upper corner of my screen, but often I have something covering this.
The time is in the toolbar, but I sometimes hide toolbars to record things. Basically, I forget what day it is and I’m looking for a few hints I can use to make this easier. As I play with PowerShell regularly, I thought it would be good to update my prompt slightly.
Plus, it would be good PoSh practice.
Setting a profile. I’ve seen a few posts on customizing the prompt, and they all say I need a function, called prompt, in my profile. I found this article, which gave me a good idea. Put the time in the prompt.
I then had to figure out how to get to my profie. It turns out “notepad $PROFILE” in a PoSh prompt will get you there. If you don’t have a profile, you’ll see this:
Say yes, and then add some code. I had to look up the Format options and experiment a bit to decide how I wanted things to look.
function prompt {
$lastResult = Invoke-Expression '$?'
if (!$lastResult) {
Write-Host "Last command exited with error status." -ForegroundColor Red
}
Write-Output "${msg}$(
# Show time as 12:05PM and day of week
Get-Date -Format "dddd HH:mm"
# Show current directory
) $(Get-Location)> "
}
I saved this and now when I get a new PoSh prompt, I get this:
Now I easily know the day and time when I’m working in a PowerShell terminal. This also shows up in my Visual Studio Code terminal as well, since that’s just a PoSh environment.
SQLNewBlogger
This was a quick thing I did in about 5 minutes to customize my environment, and help me be more productive. A happy employee works smoother.
I decided to show off how I did this and spend a quick 10 minutes writing down and documenting what I did.