Skip to content

Instantly share code, notes, and snippets.

@Fabccc
Created July 9, 2023 19:29
Show Gist options
  • Save Fabccc/c5bbb82d5cf748d98ac8ed3eb90dd677 to your computer and use it in GitHub Desktop.
Save Fabccc/c5bbb82d5cf748d98ac8ed3eb90dd677 to your computer and use it in GitHub Desktop.
Powershell profile quick setup
New-Alias l ls
New-Alias grep findstr
New-Alias wget Invoke-WebRequest
# New-Alias python python.bat
# $Folders = "".Split("\")
# $LastElement = $Folders.Count - 1
# $CmdPromptCurrentFolder = ""
# for ($i = 0; $i -lt $LastElement; $i++) {
# $Folder = $Folders[$i]
# if($Folder.Length -gt 3){
# $Folder = $Folder.Substring(0,3)
# }
# $CmdPromptCurrentFolder += +"\"
# }
# . D:\Otomny_V2\otomny_v2_wikis\procedures.wiki\.venv\Scripts\activate
# python D:\Otomny_V2\otomny_v2_wikis\procedures.wiki\info_git.py
# deactivate
function prompt {
#Assign Windows Title Text
$host.ui.RawUI.WindowTitle = "$pwd"
#Configure current user, current folder and date outputs
$Folders = $pwd.ToString().Split("\")
$LastElement = $Folders.Count - 1
$CmdPromptCurrentFolder = ""
for ($i = 0; $i -lt $LastElement; $i++) {
$Folder = $Folders[$i]
if($Folder.Length -gt 3){
$Folder = $Folder.Substring(0,3)
}
$CmdPromptCurrentFolder += $Folder +"\"
}
$CmdPromptCurrentFolder+=$Folders[$LastElement]
# $CmdPromptCurrentFolder = Split-Path -Path $pwd -Leaf
$CmdPromptUser = [Security.Principal.WindowsIdentity]::GetCurrent();
$Date = Get-Date -Format 'dddd hh:mm:ss tt'
# Test for Admin / Elevated
$IsAdmin = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
#Calculate execution time of last cmd and convert to milliseconds, seconds or minutes
$LastCommand = Get-History -Count 1
if ($LastCommand) { $RunTime = ($LastCommand.EndExecutionTime - $LastCommand.StartExecutionTime).TotalMilliseconds }
if ($RunTime -ge 60*1000) {
$ts = [timespan]::FromMilliseconds($RunTime)
$min, $sec = ($ts.ToString("mm\:ss")).Split(":")
$ElapsedTime = -join ($min, " min ", $sec, " sec")
}
else {
$ElapsedTime = [math]::Round(($RunTime), 2)
$ElapsedTime = -join (($ElapsedTime.ToString()), " ms")
}
#Decorate the CMD Prompt
Write-Host ""
Write-host ($(if ($IsAdmin) { 'Elevated ' } else { '' })) -BackgroundColor DarkRed -ForegroundColor White -NoNewline
Write-Host " USER:$($CmdPromptUser.Name.split("\")[1]) " -BackgroundColor DarkBlue -ForegroundColor White -NoNewline
If ($CmdPromptCurrentFolder -like "*:*")
{Write-Host " $CmdPromptCurrentFolder " -ForegroundColor White -BackgroundColor DarkGray -NoNewline}
else {Write-Host "|> $CmdPromptCurrentFolder\ " -ForegroundColor White -BackgroundColor DarkGray -NoNewline}
Write-Host " $date " -ForegroundColor White
Write-Host "[$elapsedTime] " -NoNewline -ForegroundColor Green
return "> "
} #end prompt function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment