Skip to content

Instantly share code, notes, and snippets.

@andregs
Last active March 2, 2019 11:28
Show Gist options
  • Save andregs/fdfcd09c4ecfd457dd43f90ee5142002 to your computer and use it in GitHub Desktop.
Save andregs/fdfcd09c4ecfd457dd43f90ee5142002 to your computer and use it in GitHub Desktop.
PowerShell script to set the user profile with quote of the day, custom prompt string, and CTRL+D shortcut to close the window
# prints quote of the day
$temp = [System.IO.Path]::GetTempPath()
$today = Get-Date -UFormat "%Y-%m-%d"
$file = "$temp\qod-$today.json"
try {
if (Test-Path $file) {
$qod = (Get-Content -Path $file | ConvertFrom-Json)
} else {
$qod = (Invoke-RestMethod http://quotes.rest/qod.json -UseDefaultCredentials).contents.quotes[0]
Set-Content -Value (ConvertTo-Json $qod) -Path "$temp\qod-$($qod.date).json"
}
} catch {
$qod = @{ quote = "Once again, I have failed to bestow a quote."; author = "System" }
}
Write-Host @"
“$($qod.quote)” ($($qod.author) - theysaidso.com)
"@ -ForegroundColor DarkCyan
# customize the prompt string with current time + current dir + >
function global:Prompt {
Write-Host (Get-Date -UFormat "%H:%M ") -NoNewline -ForegroundColor Cyan
Write-Host (Split-Path $PWD -Leaf) -NoNewline -ForegroundColor Green
return "$('>' * ($nestedPromptLevel + 1)) "
}
# set keyboard shortcut to close powershell
Set-PSReadlineKeyHandler -Chord Ctrl+D -Function DeleteCharOrExit
# References
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-5.1#how-to-create-a-profile
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_prompts?view=powershell-5.1
@andregs
Copy link
Author

andregs commented Feb 28, 2019

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment