Skip to content

Instantly share code, notes, and snippets.

@ruandre
Last active Oct 5, 2021
Embed
What would you like to do?
PowerShell Profile.ps1
# $Home\Documents\PowerShell\Profile.ps1
Clear-Host
# Install-Module PSReadLine -Scope CurrentUser
# Install-Module posh-git -Scope CurrentUser
# Install-Module oh-my-posh -Scope CurrentUser
# Install-Module -AllowClobber Get-ChildItemColor -Scope CurrentUser
# Install-Module Terminal-Icons -Scope CurrentUser
# Install-Module ZLocation -Scope CurrentUser
# Install-Module -AllowClobber Pansies -Scope CurrentUser
# https://github.com/PowerShell/PSReadLine
# https://github.com/dahlbyk/posh-git
# https://github.com/JanDeDobbeleer/oh-my-posh
# https://github.com/joonro/Get-ChildItemColor
# https://github.com/devblackops/Terminal-Icons
# https://github.com/vors/ZLocation
# https://github.com/PoshCode/Pansies
Import-Module PSReadLine
Import-Module posh-git
Import-Module oh-my-posh
Import-Module Get-ChildItemColor
Import-Module Terminal-Icons
Import-Module ZLocation
Import-Module Pansies
Set-PSReadlineOption -BellStyle None
Set-PoshPrompt -Theme star
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 2000
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineKeyHandler -Chord 'Shift+Tab' -Function Complete
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineOption -PredictionSource History
set-alias which where.exe
New-Alias -Name grep -Value Select-String
function q { exit }
# function ll { Clear-Host; Get-Location; Get-ChildItem }
function touch ($file) { Write-Output "" >> $file; }
function pcn { Write-Host $env:COMPUTERNAME }
function hosts { code C:\windows\system32\drivers\etc\hosts }
function cfg { code $Home\Documents\PowerShell\Profile.ps1 }
function rmnm() { rimraf node_modules }
function dd() { docker-compose down }
function du() { docker-compose up --build }
function dps() { docker ps }
Remove-Item alias:\gc -Force
Remove-Item alias:\gcm -Force
Remove-Item alias:\gp -Force
function g { git $args }
function gs { git status $args }
function ga { git add $args }
function gaa { git add --all $args }
function gb { git branch $args }
function gba { git branch -a $args }
function gc { git commit -v $args }
function gcm { git commit -v -m $args }
function gc! { git commit -v --amend $args }
Set-Alias gc! gc!
function gca { git commit -v -a $args }
function gco { git checkout $args }
function gd { git diff $args }
function gdca { git diff --cached $args }
function gf { git fetch $args }
function gfo { git fetch origin $args }
function gp { git pull $args }
function glg { Clear-Host; git log --stat --color $args }
function glgg { Clear-Host; git log --graph --color $args }
function glo { Clear-Host; git log --oneline --decorate --color $args }
# function glog { Clear-Host; git log --oneline --decorate --color --graph $args }
function glog() { Clear-Host; git --no-pager log --oneline --graph -n 20 --all --format=format:"%<(60,trunc)%s %Cgreen%<(40,ltrunc)%d%Creset" --date-order; Write-Output "`n" }
function gm { git merge $args }
function gsh { git show $args }
function gshp { git show --pretty=short --show-signature $args }
function mgs() { meta git status }
function mgu() { meta git update }
function mgd() { meta git diff }
function mgpa() { meta git pull --all }
function mgfa() { meta git fetch --all }
function rmeta() { rimraf node_modules; rimraf yarn.lock; lerna clean -y }
function urlencode($str_to_encode) { [uri]::EscapeDataString($str_to_encode) }
function urldecode($str_to_decode) { [uri]::UnescapeDataString($str_to_decode) }
function wget ($url) { (new-object Net.WebClient).DownloadString("$url") }
function download ($url, $file) { (new-object Net.WebClient).DownloadFile($url, $file) }
function md5 { Get-FileHash -Algorithm MD5 $args }
function sha1 { Get-FileHash -Algorithm SHA1 $args }
function sha256 { Get-FileHash -Algorithm SHA256 $args }
function base64 ($str) { [Convert]::ToBase64String([system.Text.Encoding]::UTF8.GetBytes($str)) }
# https://stackoverflow.com/a/38807689
function ch {
$havePSReadline = ($null -ne (Get-Module -EA SilentlyContinue PSReadline))
if ($havePSReadline) {
Clear-Host
if (Test-Path (Get-PSReadlineOption).HistorySavePath) {
Remove-Item -EA Stop (Get-PSReadlineOption).HistorySavePath
$null = New-Item -Type File -Path (Get-PSReadlineOption).HistorySavePath
}
Clear-History
[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()
} else {
Clear-Host
$null = [system.reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[System.Windows.Forms.SendKeys]::Sendwait('%{F7 2}')
Clear-History
}
}
# lolcat-like
# https://stackoverflow.com/a/35022366
function Get-Funky {
param([string]$Text)
# use a random colour for each character
$Text.ToCharArray() | ForEach-Object {
switch -Regex ($_) {
# ignore new line characters
"`r" {
break
}
# start a new line
"`n" {
Write-Host " "; break
}
# use random colours for displaying this non-space character
"[^ ]" {
$writeHostOptions = @{
ForegroundColor = ([system.enum]::GetValues([system.consolecolor])) | get-random
NoNewLine = $true
}
Write-Host $_ @writeHostOptions
break
}
" " { Write-Host " " -NoNewline }
}
}
}
# https://patorjk.com/software/taag/#p=display&h=2&v=2&f=Small%20Slant&t=PowerShell
$banner = "
___ ______ ____
/ _ \___ _ _____ ____/ __/ / ___ / / /
/ ___/ _ \ |/|/ / -_) __/\ \/ _ \/ -_) / /
/_/ \___/__,__/\__/_/ /___/_//_/\__/_/_/
"
function randomQuote {
$QuoteList =
"Please send all complaints to /dev/null",
"I apologize for writing a complicated program.`r`n I didn't have time to write a simple one.`r`n – Tim Sweeney`r`n",
"Talk is cheap. Show me the code. – Linus Torvalds`r`n",
"Any fool can write code that a computer can understand.`r`n Good programmers write code that humans can understand.`r`n – Martin Fowler`r`n",
"Code is like humor.`r`n When you have to explain it, it’s bad.`r`n – Cory House`r`n",
"Programs must be written for people to read,`r`n and only incidentally for machines to execute.`r`n – Harold Abelson`r`n",
"Programming is not a zero-sum game.`r`n Teaching something to a fellow programmer`r`n doesn't take it away from you.`r`n – John Carmack`r`n",
"R2D2, you know better than to trust a strange computer! – C3PO`r`n",
"Controlling complexity is the essence of computer programming.`r`n – Brian Kernigan`r`n",
"The best thing about a boolean is even if you are wrong,`r`n you are only off by a bit.`r`n",
"In order to understand recursion,`r`n one must first understand recursion.`r`n",
"Computers are like Old Testament gods;`r`n lots of rules and no mercy.`r`n – Joseph Campbell`r`n"
$Quote = Get-Random -InputObject $QuoteList
Write-Host $Quote -ForegroundColor red
}
function ll { Clear-Host; Get-Funky $banner; Get-ChildItem }
Clear-Host
Get-Funky $banner
randomQuote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment