Windows Powershell
Like bash but shit
Commands
Get Powershell Version
# display powershell version
$PSVersionTable
Who’s using my Port?
# find out process id of who's using port 8080
netstat -aon | findstr 8080
# kill task with process id XXXX
taskkill /PID XXXX /F
Powershell Profile
Add Powershell Commands that should run on startup to your profile file.
# edit users profile
notepad.exe $profile
Powershell Configuration
General Configuration
# allow execution of scripts
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser
# add profile dir to path
$ProfileRoot = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$env:path += ";$ProfileRoot"
VIM Emulation
Enable VIM Emulation in Powershell.
# change to vi readline mode
Set-PSReadlineOption -EditMode vi
# change cursor in vi mode
function OnViModeChange {
if ($args[0] -eq 'Command') {
# Set the cursor to a blinking block.
Write-Host -NoNewLine "`e[1 q"
} else {
# Set the cursor to a blinking line.
Write-Host -NoNewLine "`e[5 q"
}
}
Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange
Starship Prompt
# starship shell
Invoke-Expression (&starship init powershell)
Powershell FZF
# replace 'Ctrl+t' and 'Ctrl+r' with your preferred bindings:
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t'
Set-PsFzfOption -PSReadlineChordReverseHistory 'Ctrl+r'
Set-PsFzfOption -EnableAliasFuzzyHistory
Powershell Aliases ^d43010
Set-Alias e explorer
Set-Alias np notepad++
Set-Alias v nvim
Set-Alias vim nvim
Set-Alias dc docker-compose
Set-Alias d docker
# show container names first
Function dps { docker container ls --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}\t{{.Ports}}' }
Set-Alias java8 C:\Users\FDEJVF0\scoop\apps\temurin8-jdk\current\bin\java.exe
Set-Alias java11 C:\Users\FDEJVF0\scoop\apps\temurin11-jdk\current\bin\java.exe
Set-Alias java17 C:\Users\FDEJVF0\scoop\apps\temurin17-jdk\current\bin\java.exe
Powershell Modules
# git aliases
Install-Module -Name git-aliases -Scope CurrentUser
'Import-Module git-aliases' | Out-File -Append -Encoding default -FilePath $profile
# git autocompletion
Install-Module -Name posh-git -Scope CurrentUser
'Import-Module Posh-Git' | Out-File -Append -Encoding default -FilePath $profile
Import-Module DockerCompletion