Skip to content

Instantly share code, notes, and snippets.

@getsueineko
Last active September 12, 2025 08:30
Show Gist options
  • Select an option

  • Save getsueineko/f41499798977f879ab43f7bba8965a9f to your computer and use it in GitHub Desktop.

Select an option

Save getsueineko/f41499798977f879ab43f7bba8965a9f to your computer and use it in GitHub Desktop.
#
## PowerShell
### PowerShell User Profile
#
### Constants
$PROFILE_ROOT = $PROFILE | Split-Path
$SSH_KEY_PATH = "$env:USERPROFILE\.ssh\id_ed25519.pub"
$HOSTS_PATH = "$env:SystemRoot\System32\drivers\etc\hosts"
$VSCODE_PATH = "C:\Program Files\Microsoft VS Code\Code.exe"
$NEOVIM_PATH = "$env:USERPROFILE\scoop\shims\nvim.exe"
$NSLOOKUP_PATH = "C:\ProgramData\chocolatey\lib\bind-toolsonly\tools\content\nslookup.exe"
### Import-Module
### Check dependencies
$requiredModules = @('posh-git', 'PSReadLine', 'Terminal-Icons', 'PSFzf', 'z', 'PoShFuck')
foreach ($module in $requiredModules) {
if (-not (Get-Module -ListAvailable $module)) {
Write-Warning "The $module is not installed. Use 'Install-Module $module'"
}
}
Import-Module -Name Get-ChildItemColor
Import-Module -Name PSReadLine
Import-Module -Name z
Import-Module -Name Terminal-Icons
Import-Module -Name posh-git
# When you type a command incorrectly, don't say 'fuck', type it!
Import-Module PoShFuck
# fzf power
Import-Module PSFzf
### Functions
Function SSHPubkey {
$remoteHost = Read-Host -Prompt 'Enter user@ip-address'
Get-Content $SSH_KEY_PATH | ssh $remoteHost "cat >> ~/.ssh/authorized_keys"
}
Function Change-Hosts {
sudo nano $env:SystemRoot\System32\drivers\etc\hosts
}
Function Git-Pull {
git.exe pull; if ($?) { Clear-Host }
}
Function Git-Push {
try {
git add . &&
git commit -m "Quick commit $(Get-Date -Format 'HH:mm')" &&
git push
Clear-Host
Write-Host "✅ Push completed" -ForegroundColor Cyan
} catch {
Write-Error "Git operation failed: $_"
}
}
Function Git-Status {
git.exe status
}
Function Clean-Temp {
Remove-Item -Path $env:TEMP\* -Recurse -ErrorAction SilentlyContinue
}
Function Which ($command) {
Get-Command -Name $command -ErrorAction SilentlyContinue |
Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
Function Update-All-Wingets {
winget.exe upgrade --recurse --source winget --verbose
}
# Helper function to change directory to my development workspace
# Change c:\ws to your usual workspace and everytime you type
# in cws from PowerShell it will take you directly there.
function Go-Tmp {
if (Test-Path c:\Temp) { Set-Location c:\Temp }
}
# Helper function to set location to the User Profile directory
function Go-Home {
Set-Location ~
}
# Helper function to set alias for VS Code
# Set-Alias -Name vsc -Value 'C:\Program Files\Microsoft VS Code\Code.exe'
# Helper function to show Unicode character
function U
{
param
(
[int] $Code
)
if ((0 -le $Code) -and ($Code -le 0xFFFF))
{
return [char] $Code
}
if ((0x10000 -le $Code) -and ($Code -le 0x10FFFF))
{
return [char]::ConvertFromUtf32($Code)
}
throw "Invalid character code $Code"
}
function y {
$tmp = [System.IO.Path]::GetTempFileName()
yazi $args --cwd-file="$tmp"
$cwd = Get-Content -Path $tmp -Encoding UTF8
if (-not [String]::IsNullOrEmpty($cwd) -and $cwd -ne $PWD.Path) {
Set-Location -LiteralPath ([System.IO.Path]::GetFullPath($cwd))
}
Remove-Item -Path $tmp
}
### Alias
Set-Alias ~ Go-Home -Option AllScope
Set-Alias -Name vim -Value $NEOVIM_PATH
Set-Alias -Name vsc -Value $VSCODE_PATH
Set-Alias -Name cle -Value Clear-Host
Set-Alias -Name cln -Value Clean-Temp
Set-Alias -Name touch -Value New-Item
Set-Alias -Name ua -Value Update-All-Wingets
Set-Alias -Name gst -Value Git-Status
Set-Alias -Name gsh -Value Git-Push
Set-Alias -Name gll -Value Git-Pull
Set-Alias -Name hosts -Value Change-Hosts
Set-Alias -Name pubkey -Value SSHPubkey
Set-Alias -Name nslookup -Value $NSLOOKUP_PATH
# Set l and ls alias to use the new Get-ChildItemColor cmdlets
Set-Alias ls Get-ChildItemColor -Option AllScope
Set-Alias l Get-ChildItemColorFormatWide -Option AllScope
### Setup PSReadLineOption
# Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -HistoryNoDuplicates:$True
Set-PSReadLineOption -ShowToolTips:$True
# Get KeyHandlers 'Get-PSReadLineKeyHandler -Bound -Unbound'
Set-PSReadlineKeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineKeyHandler -Chord 'Ctrl+f' -Function ForwardWord
Set-PSReadLineKeyHandler -Chord 'Enter' -Function ValidateAndAcceptLine
# Override default tab completion
Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion }
# Override PSReadLine's history search
Set-PsFzfOption -PSReadlineChordProvider 'Ctrl+t' `
-PSReadlineChordReverseHistory 'Ctrl+r'
# Default the prompt to agnoster oh-my-posh theme
# oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\emodipt-extend.omp.json" | Invoke-Expression
oh-my-posh init pwsh --config "$env:USERPROFILE\scoop\persist\oh-my-posh\themes\negligible-ai.omp.json" | Invoke-Expression
### Animated "live" PowerShell welcome message
$commands = @(
"gsh → Git-Push",
"hosts → Change-Hosts",
"pubkey → SSHPubkey",
"clean → Clean-Temp"
)
Write-Host "`n🎯 PowerShell profile loaded! 🎯" -ForegroundColor Cyan
Write-Host "🚀 Quick commands:" -ForegroundColor Yellow
foreach ($cmd in $commands) {
Write-Host " $cmd" -ForegroundColor DarkGray -NoNewline
Start-Sleep -Milliseconds 100
Write-Host "`r $cmd" -ForegroundColor Green
Start-Sleep -Milliseconds 100
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment