Skip to content

Instantly share code, notes, and snippets.

@ruandre
Last active September 23, 2023 15:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruandre/2310e500ac7afb1ea0bff041407cb233 to your computer and use it in GitHub Desktop.
Save ruandre/2310e500ac7afb1ea0bff041407cb233 to your computer and use it in GitHub Desktop.
PowerShell Profile.ps1
# ___ ______ ____
# / _ \___ _ _____ ____/ __/ / ___ / / /
# / ___/ _ \ |/|/ / -_) __/\ \/ _ \/ -_) / /
# /_/ \___/__,__/\__/_/ /___/_//_/\__/_/_/
#
# https://github.com/PowerShell/PowerShell
# %USERPROFILE%\Documents\PowerShell\Profile.ps1
# https://github.com/PowerShell/PSReadLine
# https://github.com/dahlbyk/posh-git
# https://github.com/JanDeDobbeleer/oh-my-posh
# 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 Terminal-Icons
Import-Module ZLocation
Import-Module Pansies
Set-PSReadlineOption -BellStyle None
Set-PSReadLineOption -HistoryNoDuplicates
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
Set-PSReadLineOption -MaximumHistoryCount 2000
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView
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-PoshPrompt -Theme star
# https://github.com/sharkdp/bat
Set-Alias cat bat.exe
Set-Alias which where.exe
Set-Alias -Name grep -Value Select-String
function touch ($file) { Write-Output "" >> $file; }
function q() { exit }
function pcn { Write-Host $env:COMPUTERNAME }
function hosts { code C:\windows\system32\drivers\etc\hosts }
function b { bash }
function wslrn { Restart-NetAdapter -Name "vEthernet (WSL)" }
function wslr { wsl -l -v; wsl --shutdown; wsl -l -v }
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 gbr() { git branch -vr }
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 gfa() { git fetch --all }
function gfo { git fetch origin $args }
function gp { git pull $args }
function gpa() { git pull --all }
function grv() { git remote -v }
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 glt() { 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 grl() { git rev-list --all --count }
function gsl() { git shortlog -s -n }
function gm { git merge $args }
function gsh { git show $args }
function gshp { git show --pretty=short --show-signature $args }
function rmnm() { rimraf node_modules }
function npmls () { npm ls --depth 0 }
function npmlg () { npm ls -g --depth 0 }
function npmv ($package) { npm view $package versions --json }
function nrs() { Clear-Host; npm run serve }
function nrl() { Clear-Host; npm run lint }
function nrt() { Clear-Host; npm run test }
function nrb() { Clear-Host; npm run build }
function cz() { Clear-Host; npm run cz }
function rmeta() { rimraf node_modules; rimraf yarn.lock; lerna clean -y }
function ys() { Clear-Host; yarn start }
function mgs() { meta git status }
function mgu() { meta git update }
function mgd() { meta git diff }
function mgp() { meta git pull --all }
function mgf() { meta git fetch --all }
function exc() { Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force }
function dps() { docker ps }
function dd() { docker-compose down }
function dub() { docker-compose up --build }
function dur() { docker-compose up --build --force-recreate -d }
function dlg ($container) { docker logs -f $container }
function dsh ($container) { docker exec -it $container sh }
function wget ($url) { (new-object Net.WebClient).DownloadString("$url") }
function download ($url, $file) { (new-object Net.WebClient).DownloadFile($url, $file) }
function urlencode($str_to_encode) { [uri]::EscapeDataString($str_to_encode) }
function urldecode($str_to_decode) { [uri]::UnescapeDataString($str_to_decode) }
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)) }
function base64img ($path) { [convert]::ToBase64String((get-content $path -encoding byte)) }
function base64dir () { Get-ChildItem -File | Foreach { base64img $_.fullname | Out-File -Append ./out.txt } }
# clear history
# 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 {
$list =
"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 $list
Write-Host "`r`nQuote of the day:`r`n" -ForegroundColor green
Write-Host $quote -ForegroundColor yellow
}
# list
function ll() { Clear-Host; Get-Funky $banner; randomQuote; Get-ChildItem }
#function ll() { Clear-Host; Get-Funky $banner; randomQuote; Get-ChildItem; Get-Location }
# on open
ll
# https://starship.rs/
Invoke-Expression (&starship init powershell)
@ruandre
Copy link
Author

ruandre commented Dec 1, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment