Skip to content

Instantly share code, notes, and snippets.

@yorek
Last active April 6, 2018 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorek/cfa9e9c4ab5384d5117f3c74165a654b to your computer and use it in GitHub Desktop.
Save yorek/cfa9e9c4ab5384d5117f3c74165a654b to your computer and use it in GitHub Desktop.
Powershell Profile
# Taken from https://joonro.github.io/blog/posts/powershell-customizations.html
# and https://hodgkins.io/ultimate-powershell-prompt-and-git-setup
Import-Module posh-git
Import-Module Get-ChildItemColor
Import-Module PSReadLine
$global:GitPromptSettings.BeforeText = '['
$global:GitPromptSettings.AfterText = '] '
# Set aliases
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
Set-Alias npp "C:\Program Files (x86)\Notepad++\notepad++.exe" -option ReadOnly
# Configure 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
# http://serverfault.com/questions/95431
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
# https://github.com/dahlbyk/posh-git/wiki/Customizing-Your-PowerShell-Prompt
$origLastExitCode = $LastExitCode
if (Test-Administrator) { # if elevated
Write-Host "(Admin) " -NoNewline -ForegroundColor White
}
Write-Host "$env:USERNAME@" -NoNewline -ForegroundColor DarkYellow
Write-Host "$env:COMPUTERNAME" -NoNewline -ForegroundColor Magenta
Write-Host " : " -NoNewline -ForegroundColor DarkGray
$curPath = $ExecutionContext.SessionState.Path.CurrentLocation.Path
if ($curPath.ToLower().StartsWith($Home.ToLower()))
{
$curPath = "~" + $curPath.SubString($Home.Length)
}
Write-Host $curPath -NoNewline -ForegroundColor Blue
Write-Host " : " -NoNewline -ForegroundColor DarkGray
Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor DarkMagenta
Write-Host " : " -NoNewline -ForegroundColor DarkGray
Write-VcsStatus
$LastExitCode = $origLastExitCode
"`n$('>' * ($nestedPromptLevel + 1)) "
}
filter xargs
{
& $args[0] ($args[1..$args.length] + $_)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment