Last active
April 6, 2018 00:18
-
-
Save yorek/cfa9e9c4ab5384d5117f3c74165a654b to your computer and use it in GitHub Desktop.
Powershell Profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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