PoshCode Archive  Artifact [6d62af1817]

Artifact 6d62af1817d160d3268260e45e807cb328223d3a6132ba28dbc03f2310acac01:

  • File coolprompt.ps1 — part of check-in [f389be45a9] at 2018-06-10 13:01:12 on branch trunk — A cool prompt function. Insert code into your profile script (“C:\Users\%username%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”). Must use Consolas font in powershell (set font, then restart powershell) for special characters to appear correctly. Displays path + uptime in title, example prompt as: jgentile@quadbox●~\powershell► (user: unknown size: 1402)

# encoding: ascii
# api: powershell
# title: coolprompt
# description: A cool prompt function.  Insert code into your profile script (“C:\Users\%username%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1”).  Must use Consolas font in powershell (set font, then restart powershell) for special characters to appear correctly.  Displays path + uptime in title, example prompt as: jgentile@quadbox●~\powershell►
# version: 0.1
# type: class
# license: CC0
# x-poshcode-id: 1788
# x-archived: 2010-04-25T07:49:55
#
#

	$global:wmilocalcomputer = get-WMIObject -class Win32_OperatingSystem -computer "."
	$global:lastboottime=[System.Management.ManagementDateTimeconverter]::ToDateTime($wmilocalcomputer.lastbootuptime)
	$global:originaltitle = [console]::title

function prompt 
{
	$up=$(get-date)-$lastboottime

	$upstr="$([datetime]::now.toshorttimestring()) $([datetime]::now.toshortdatestring()) up $($up.days) days, $($up.hours) hours, $($up.minutes) minutes"

	$dir = $pwd.path

	$homedir = (get-psprovider 'FileSystem').home

	if ($homedir -ne "" -and $dir.toupper().startswith($homedir.toupper()))
	{
		$dir=$dir.remove(0,$homedir.length).insert(0,'~')
	}
	
	$retstr = "$env:username@$($env:computername.tolower())●$dir" 

	[console]::title = "$global:originaltitle ♦ $retstr ♦ $upstr" 

	return "$retstr►"
}