Skip to content

Instantly share code, notes, and snippets.

@bkataru
Created September 25, 2025 05:31
Show Gist options
  • Select an option

  • Save bkataru/eccdc9c1ceb8eb776f8aec0023dc5279 to your computer and use it in GitHub Desktop.

Select an option

Save bkataru/eccdc9c1ceb8eb776f8aec0023dc5279 to your computer and use it in GitHub Desktop.
Microsoft.PowerShell_profile.ps1 on da threadripper
Import-Module Terminal-Icons
Import-Module posh-git
function prompt {
function Get-CPUUsage {
$cpu = Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty LoadPercentage
return $cpu
}
function Get-MemoryUsage {
$mem = Get-CimInstance -ClassName Win32_OperatingSystem
$total = $mem.TotalVisibleMemorySize
$free = $mem.FreePhysicalMemory
$used = $total - $free
$percent = ($used / $total) * 100
return [math]::Round($percent, 2)
}
function Get-DiskUsage {
$disk = Get-PSDrive -Name C
$used = $disk.Used / 1GB
$total = ($disk.Used + $disk.Free) / 1GB
$percent = ($used / $total) * 100
return [math]::Round($percent, 2)
}
$env:CPU_USAGE = Get-CPUUsage
$env:MEM_USAGE = Get-MemoryUsage
$env:DISK_USAGE = Get-DiskUsage
$env:ZIG_VERSION = "0.14.0"
oh-my-posh --init --shell pwsh --config ~/AppData/Local/Programs/oh-my-posh/themes/tron-legacy.omp.json | Invoke-Expression
}
prompt
function fetch {
Set-Alias winfetch pwshfetch-test-1
Set-Alias ffetch fastfetch
}
fetch
function ps_read_line {
Import-Module PSReadLine
# shows navigable menu of all options when hitting Tab
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# autocompletion for Arrow keys
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -ShowToolTips
Set-PSReadLineOption -PredictionSource History
}
ps_read_line
function ps_fzf {
Import-Module PsFzf
# `Ctrl+f` searches files, `Ctrl+r` searches command history
Set-PsFzfOption -PsReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'
}
ps_fzf
function zoxide_init { Invoke-Expression (& { (zoxide init powershell | Out-String) }) }
zoxide_init
function remove_aliases {
If (Test-Path Alias:curl) {Remove-Item Alias:curl}
If (Test-Path Alias:wget) {Remove-Item Alias:wget}
}
remove_aliases
function hosts_quick_edit {
# hosts file quick edit with notepad
function Global:np_hosts { notepad C:\Windows\System32\Drivers\etc\hosts }
# hosts file quick edit with micro
function Global:mu_hosts { micro C:\Windows\System32\Drivers\etc\hosts }
# hosts file quick edit with lapce
function Global:lps_hosts { Lapce C:\Windows\System32\Drivers\etc\hosts }
}
hosts_quick_edit
function profile_quick_edit {
# $PROFILE file quick edit with notepad
function Global:np_profile { notepad $PROFILE }
# $PROFILE file quick edit with micro
function Global:mu_profile { micro $PROFILE }
# $PROFILE file quick edit with lapce
function Global:lps_profile { Lapce $PROFILE }
}
profile_quick_edit
# generate single-file .txt context compiling all files in a given directory
function contxtgen {
C:\Development\scripts\contxtgen.ps1 @args
}
fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
@bkataru
Copy link
Author

bkataru commented Sep 25, 2025

new, optimized, cleaned up, starship-powered Microsoft.PowerShell_profile.ps1

# Threadripper Profile - PowerShell 5.1 Compatible

# Initialize Starship prompt
try {
    Invoke-Expression (&starship init powershell)
    Write-Host "Starship prompt initialized" -ForegroundColor Green
}
catch {
    Write-Warning "Starship not found"
}

# PSReadLine configuration
if (Get-Module -ListAvailable -Name PSReadLine) {
    Import-Module PSReadLine -Force
    Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
    Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
    Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
    Set-PSReadLineOption -ShowToolTips
    Set-PSReadLineOption -PredictionSource History
    Write-Host "PSReadLine configured" -ForegroundColor Green
}

# System monitoring function
function Get-SystemStats {
    $cpu = Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty LoadPercentage
    $mem = Get-CimInstance -ClassName Win32_OperatingSystem
    $total = $mem.TotalVisibleMemorySize
    $free = $mem.FreePhysicalMemory
    $used = $total - $free
    $memPercent = [math]::Round(($used / $total) * 100, 2)
    
    $disk = Get-PSDrive -Name C
    $diskUsed = $disk.Used / 1GB
    $diskTotal = ($disk.Used + $disk.Free) / 1GB
    $diskPercent = [math]::Round(($diskUsed / $diskTotal) * 100, 2)
    
    [PSCustomObject]@{
        CPU       = "$cpu%"
        Memory    = "$memPercent%"
        Disk      = "$diskPercent%"
        Timestamp = Get-Date -Format "HH:mm:ss"
    }
}

Set-Alias -Name sysinfo -Value Get-SystemStats

# Node.js version management
if (Get-Command fnm -ErrorAction SilentlyContinue) {
    fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
    Write-Host "Node.js manager (fnm) initialized" -ForegroundColor Green
}

# Zoxide navigation
if (Get-Command zoxide -ErrorAction SilentlyContinue) {
    Invoke-Expression (& { (zoxide init powershell | Out-String) })
    Write-Host "Zoxide initialized" -ForegroundColor Green
}

# Quick edit functions
function Global:np_hosts { notepad C:\Windows\System32\Drivers\etc\hosts }
function Global:mu_hosts { micro C:\Windows\System32\Drivers\etc\hosts }
function Global:lps_hosts { Lapce C:\Windows\System32\Drivers\etc\hosts }

function Global:np_profile { notepad $PROFILE }
function Global:mu_profile { micro $PROFILE }
function Global:lps_profile { Lapce $PROFILE }

# Context generation utility
if (Test-Path "C:\Development\scripts\contxtgen.ps1") {
    function contxtgen {
        C:\Development\scripts\contxtgen.ps1 @args
    }
}

# Optional modules
function Initialize-TerminalIcons {
    if (Get-Module -ListAvailable -Name Terminal-Icons) {
        Import-Module Terminal-Icons
        Write-Host "Terminal Icons loaded" -ForegroundColor Green
    }
}

function Initialize-PoshGit {
    if (Get-Module -ListAvailable -Name posh-git) {
        Import-Module posh-git
        Write-Host "Posh-Git loaded" -ForegroundColor Green
    }
}

function Initialize-PsFzf {
    if (Get-Module -ListAvailable -Name PsFzf) {
        Import-Module PsFzf
        Set-PsFzfOption -PsReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'
        Write-Host "PsFzf configured" -ForegroundColor Green
    }
}

# Display startup time (PowerShell 5.1 compatible)
try {
    if ($PSCommandStartTime) {
        $startupTime = [math]::Round(((Get-Date) - $PSCommandStartTime).TotalMilliseconds, 0)
        Write-Host "PowerShell profile loaded in ${startupTime}ms" -ForegroundColor Cyan
    }
    else {
        Write-Host "PowerShell profile loaded successfully" -ForegroundColor Cyan
    }
}
catch {
    Write-Host "PowerShell profile loaded successfully" -ForegroundColor Cyan
}

Write-Host "Quick Reference:" -ForegroundColor Yellow
Write-Host "- Load modules: Initialize-TerminalIcons, Initialize-PoshGit, Initialize-PsFzf" -ForegroundColor Gray
Write-Host "- System stats: sysinfo" -ForegroundColor Gray
Write-Host "- Edit hosts: np_hosts, mu_hosts, lps_hosts" -ForegroundColor Gray
Write-Host "- Edit profile: np_profile, mu_profile, lps_profile" -ForegroundColor Gray

associated starship.toml

# =============================================================================
# Starship Configuration - Optimized for Performance and Usability
# =============================================================================
# This configuration provides a fast, informative, and visually appealing prompt
# Documentation: https://starship.rs/config/

# =============================================================================
# GENERAL SETTINGS
# =============================================================================
format = """
[╭╮](bold blue)\
$username\
$hostname\
$directory\
$git_branch\
$git_state\
$git_status\
$nodejs\
$python\
$rust\
$golang\
$java\
$php\
$memory_usage\
$cmd_duration\
$line_break\
$character"""

# Add a new line before the prompt
add_newline = true

# =============================================================================
# PROMPT CHARACTER
# =============================================================================
[character]
success_symbol = "[╰─➤](bold green)"
error_symbol = "[╰─✗](bold red)"
vicmd_symbol = "[╰─❮](bold yellow)"

# =============================================================================
# DIRECTORY
# =============================================================================
[directory]
style = "bold cyan"
truncation_length = 3
truncation_symbol = "…/"
home_symbol = "🏠"
read_only_style = "red"
read_only = "🔒"

# =============================================================================
# GIT BRANCH
# =============================================================================
[git_branch]
symbol = "🌱 "
style = "bold green"
format = "on [$symbol$branch]($style) "
truncation_length = 20
truncation_symbol = ""

# =============================================================================
# GIT STATUS
# =============================================================================
[git_status]
style = "bold red"
format = "([\\[$all_status$ahead_behind\\]]($style) )"
conflicted = "🏳"
ahead = "🏃💨"
behind = "🐌"
diverged = "🔀"
up_to_date = ""
untracked = "🤷"
stashed = "📦"
modified = "📝"
staged = "🎯"
renamed = "📛"
deleted = "🗑"

# =============================================================================
# GIT STATE
# =============================================================================
[git_state]
format = '[\($state( $progress_current of $progress_total)\)]($style) '
style = "bold yellow"
rebase = "REBASING"
merge = "MERGING"
revert = "REVERTING"
cherry_pick = "CHERRY-PICKING"
bisect = "BISECTING"
am = "AM"
# rebase_merge = "REBASE-MERGE"  # Removed - not supported in this version
# progress_divider = "/"  # Removed - not supported in this version

# =============================================================================
# USERNAME
# =============================================================================
[username]
style_user = "bold blue"
style_root = "bold red"
format = "[$user]($style) "
disabled = false
show_always = true

# =============================================================================
# HOSTNAME
# =============================================================================
[hostname]
ssh_only = false
format = "on [$hostname](bold yellow) "
disabled = false

# =============================================================================
# NODE.JS
# =============================================================================
[nodejs]
symbol = ""
format = "via [$symbol($version )]($style)"
style = "bold green"
detect_extensions = ["js", "mjs", "ts", "jsx", "tsx", "json"]
detect_files = ["package.json", ".node-version", ".nvmrc"]
detect_folders = ["node_modules"]

# =============================================================================
# PYTHON
# =============================================================================
[python]
symbol = "🐍 "
format = "via [$symbol($version )]($style)"
style = "bold yellow"
detect_extensions = ["py", "pyc", "pyo", "pyd", "pyi", "pyw", "pyz"]
detect_files = ["requirements.txt", "pyproject.toml", "poetry.lock", "Pipfile", "tox.ini", "setup.py", "setup.cfg", "pyrightconfig.json"]
detect_folders = ["__pycache__", ".venv", ".mypy_cache", ".pytest_cache", ".ruff_cache"]

# =============================================================================
# RUST
# =============================================================================
[rust]
symbol = "🦀 "
format = "via [$symbol($version )]($style)"
style = "bold red"
detect_extensions = ["rs"]
detect_files = ["Cargo.toml", "Cargo.lock"]

# =============================================================================
# GOLANG
# =============================================================================
[golang]
symbol = "🐹 "
format = "via [$symbol($version )]($style)"
style = "bold cyan"
detect_extensions = ["go"]
detect_files = ["go.mod", "go.sum", "glide.yaml", "Gopkg.yml", "Gopkg.lock", ".go-version"]
detect_folders = ["vendor"]

# =============================================================================
# JAVA
# =============================================================================
[java]
symbol = ""
format = "via [$symbol($version )]($style)"
style = "bold red"
detect_extensions = ["java", "class", "jar", "gradle", "clj", "cljc"]
detect_files = ["pom.xml", "build.gradle", "build.sbt", ".java-version", "deps.edn", "project.clj", "build.boot", "gradle.properties", "gradlew", "maven-wrapper.properties"]

# =============================================================================
# PHP
# =============================================================================
[php]
symbol = "🐘 "
format = "via [$symbol($version )]($style)"
style = "bold blue"
detect_extensions = ["php", "phtml", "php3", "php4", "php5", "php7", "php8", "phps"]
detect_files = ["composer.json", "composer.lock", ".php-version", "artisan", "wp-config.php", "phpunit.xml", ".phpunit.result.cache", "phpcs.xml", "psr4.json", "composer.lock", "composer.json", ".phpunit.result.cache", "phpunit.xml", "psr4.json", "phpcs.xml", "wp-config.php", "artisan", ".php-version"]

# =============================================================================
# MEMORY USAGE
# =============================================================================
[memory_usage]
disabled = false
threshold = 70
symbol = "🐏 "
format = "via $symbol [${ram}( | ${swap})]($style) "
style = "bold dimmed red"

# =============================================================================
# COMMAND DURATION
# =============================================================================
[cmd_duration]
min_time = 2_000
format = "took [$duration]($style) "
style = "bold yellow"
show_milliseconds = false

# =============================================================================
# LINE BREAK
# =============================================================================
[line_break]
disabled = false

# =============================================================================
# PERFORMANCE OPTIMIZATIONS
# =============================================================================
# Disable modules that might slow down the prompt
[aws]
disabled = true

[azure]
disabled = true

[gcloud]
disabled = true

[kubernetes]
disabled = true

[terraform]
disabled = true

[conda]
disabled = true

[spack]
disabled = true

# =============================================================================
# CUSTOM MODULES (Optional)
# =============================================================================
# Uncomment and customize these if needed:

# [custom.sysinfo]
# command = "powershell -NoProfile -Command \"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize\""
# when = "true"
# symbol = "💻 "
# style = "bold blue"
# format = "via [$symbol$output]($style) "

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