Skip to content

Instantly share code, notes, and snippets.

@rdbartram
Created June 19, 2018 12:46
Show Gist options
  • Save rdbartram/a940cf606a99c719f1ed143c9fb8172b to your computer and use it in GitHub Desktop.
Save rdbartram/a940cf606a99c719f1ed143c9fb8172b to your computer and use it in GitHub Desktop.
# Import module from previous step
Import-Module -Name posh-git
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
Write-Host
# Reset color, which can be messed up by Enable-GitColors
#$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
if (Test-Administrator) {
# Use different username if elevated
Write-Host "(Elevated) " -NoNewline -ForegroundColor White
}
if ($s -ne $null) {
# color for PSSessions
Write-Host " (`$s: " -NoNewline -ForegroundColor DarkGray
Write-Host "$($s.Name)" -NoNewline -ForegroundColor Yellow
Write-Host ") " -NoNewline -ForegroundColor DarkGray
Write-Host " : " -NoNewline -ForegroundColor DarkGray
}
Write-Host $($(Get-Location) -replace ($env:USERPROFILE).Replace('\', '\\'), "~") -NoNewline -ForegroundColor Blue
Write-Host " : " -NoNewline -ForegroundColor DarkGray
Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor DarkMagenta
Write-Host " : " -NoNewline -ForegroundColor DarkGray
$global:LASTEXITCODE = $realLASTEXITCODE
Write-VcsStatus
$command = Get-History -Count 1
Write-Host " Execution Time: $($command.EndExecutionTime - $command.StartExecutionTime)" -NoNewline -ForegroundColor DarkGray
Write-Host ""
return "> "
}
New-PSDrive -Name Github -PSProvider FileSystem -Root C:\Repos\Github | Out-Null
New-PSDrive -Name Geberit -PSProvider FileSystem -Root C:\Repos\Geberit | Out-Null
New-PSDrive -Name HIAG -PSProvider FileSystem -Root C:\Repos\HIAG | Out-Null
New-PSDrive -Name itnetX -PSProvider FileSystem -Root C:\Repos\itnetX | Out-Null
Set-Alias ls Get-ChildItemColor -option AllScope -Force
Set-Alias dir Get-ChildItemColor -option AllScope -Force
Import-Module PSReadLine
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 4000
# history substring search
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
# Tab completion
Set-PSReadlineKeyHandler -Chord 'Shift+Tab' -Function Complete
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
function cddash {
if ($args[0] -eq '-') {
$pwd = $OLDPWD;
} else {
$pwd = $args[0];
}
$tmp = pwd;
if ($pwd) {
Set-Location $pwd;
}
Set-Variable -Name OLDPWD -Value $tmp -Scope global;
}
Set-Alias -Name cd -value cddash -Option AllScope
$global:GitPromptSettings.BranchAheadStatusForegroundColor = [ConsoleColor]::Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment