Bash (wsl and standard)
just copy paste
# =========================================================
# PROMPT bash (WSL/Linux) — dwuliniowy z LAN/WAN IP
# Linia 1: ✔/✘ 🕒 godzina user@host
# Linia 2: 📁 Rodzic/Bieżący 📶/🖧 LAN 🌍 WAN $/#
# =========================================================
# --- Rodzic/Bieżący
__short_path() {
local loc="${PWD}"
local parent base
if [[ "$loc" == "$HOME" ]]; then
echo "~"
return
fi
parent=$(basename "$(dirname "$loc")")
base=$(basename "$loc")
if [[ -z "$parent" || "$parent" == "/" ]]; then
echo "$loc"
else
echo "$parent/$base"
fi
}
# --- LAN IP (📶 WiFi / 🖧 kabel)
__lan_ip() {
local iface ip icon
while IFS= read -r iface; do
[[ "$iface" =~ ^(lo|docker|veth|br-|virbr) ]] && continue
ip=$(ip -4 addr show "$iface" 2>/dev/null \
| awk '/inet / {print $2}' \
| cut -d/ -f1 \
| grep -v '^169\.254' \
| head -1)
[[ -n "$ip" ]] && break
done < <(ip -o link show up 2>/dev/null \
| awk -F': ' '{print $2}' \
| cut -d@ -f1)
if [[ -z "$ip" ]]; then
echo "🖧 -"
return
fi
if [[ "$iface" =~ ^(wlan|wlp|wlx) ]]; then
icon="📶"
else
icon="🖧"
fi
echo "$icon $ip"
}
# --- WAN IP — cachowany co 5 minut
__WAN_IP=""
__WAN_LAST=0
__wan_ip() {
local now
now=$(date +%s)
if [[ -n "$__WAN_IP" && $(( now - __WAN_LAST )) -lt 300 ]]; then
echo "$__WAN_IP"
return
fi
local ip
ip=$(curl -s --max-time 3 "https://ifconfig.me" 2>/dev/null)
if [[ -n "$ip" ]]; then
__WAN_IP="$ip"
__WAN_LAST=$now
echo "$ip"
else
echo "${__WAN_IP:--}"
fi
}
# --- Czas wykonania komendy (tylko >1s)
__CMD_START=0
__timer_start() {
[[ "$BASH_COMMAND" == "__build_prompt" ]] && return
__CMD_START=$(date +%s%3N)
}
__timer_stop() {
local now elapsed_ms
now=$(date +%s%3N)
(( __CMD_START == 0 )) && { __ELAPSED=""; return; }
elapsed_ms=$(( now - __CMD_START ))
__CMD_START=0
if (( elapsed_ms < 1000 )); then
__ELAPSED=""
return
fi
local h m s
s=$(( elapsed_ms / 1000 ))
h=$(( s / 3600 )); s=$(( s % 3600 ))
m=$(( s / 60 )); s=$(( s % 60 ))
__ELAPSED=""
(( h > 0 )) && __ELAPSED+="${h}h "
(( m > 0 )) && __ELAPSED+="${m}m "
(( s > 0 )) && __ELAPSED+="${s}s"
__ELAPSED="${__ELAPSED% }"
}
trap '__timer_start' DEBUG
# --- Główny prompt
__build_prompt() {
local exit_code=$?
__timer_stop
local status_char main_clr symbol
if (( exit_code == 0 )); then
status_char="✔"
else
status_char="✘"
fi
if (( EUID == 0 )); then
symbol="#"; main_clr="31"
else
symbol="$"; main_clr="32"
fi
# Elapsed
local elapsed_seg=""
[[ -n "$__ELAPSED" ]] && elapsed_seg=" \e[90m⏱ ${__ELAPSED}\e[0m"
# Linia 1
local line1
line1="\e[${main_clr}m${status_char}\e[0m${elapsed_seg} \e[34m🕒 $(date '+%H:%M:%S')\e[0m \e[36m${USER}@${HOSTNAME}\e[0m"
# Linia 2
local path lan wan
path=$(__short_path)
lan=$(__lan_ip)
wan=$(__wan_ip)
local line2
line2="\e[1m\e[${main_clr}m📁 ${path}\e[0m \e[33m${lan}\e[0m \e[33m🌍 ${wan}\e[0m \e[${main_clr}m${symbol}\e[0m "
PS1="$(printf "%b" "$line1")\n$(printf "%b" "$line2")"
}
PROMPT_COMMAND='__build_prompt'
# --- Aliasy
alias ll='ls -lah --color=auto'
alias la='ls -A --color=auto'
alias l='ls -CF --color=auto'
alias reload='source ~/.bashrc && echo "✓ .bashrc reloaded"'
powershell 5.x
# =========================================================
# PROMPT PS 5.1 — dwuliniowy z LAN/WAN IP
# Linia 1: ✔/✘ 🕒 godzina user@host
# Linia 2: 📁 Rodzic\Bieżący 📶/🖧 LAN 🌍 WAN $/#
# =========================================================
try { $host.PrivateData.StartupBanner = "" } catch {}
# --- Admin?
function Test-IsAdmin {
try {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object Security.Principal.WindowsPrincipal($id)
return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
} catch { return $false }
}
# --- Rodzic\Bieżący
function Get-ShortPath {
$loc = (Get-Location).Path
try { $item = Get-Item -LiteralPath $loc -ErrorAction Stop } catch { return $loc }
if ($null -eq $item.Parent) { return $item.FullName }
return "$($item.Parent.Name)\$($item.Name)"
}
# --- LAN IP (📶 WiFi / 🖧 kabel)
function Get-LanIP {
try {
$excluded = @('Loopback', 'Tunnel')
$iface = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() |
Where-Object {
$_.OperationalStatus -eq 'Up' -and
$_.NetworkInterfaceType.ToString() -notin $excluded -and
$_.Name -notmatch 'WSL|Hyper-V|vEthernet|Loopback'
} |
Where-Object {
$null -ne ($_.GetIPProperties().UnicastAddresses |
Where-Object {
$_.Address.AddressFamily.ToString() -eq 'InterNetwork' -and
$_.Address.ToString() -notmatch '^169\.254'
} |
Select-Object -First 1)
} |
Select-Object -First 1
if (-not $iface) { return [PSCustomObject]@{ IP = "-"; Icon = "🖧" } }
$ip = $iface.GetIPProperties().UnicastAddresses |
Where-Object { $_.Address.AddressFamily.ToString() -eq 'InterNetwork' } |
Select-Object -First 1
$icon = if ($iface.NetworkInterfaceType.ToString() -eq 'Wireless80211') { "📶" } else { "🖧" }
return [PSCustomObject]@{ IP = $ip.Address.ToString(); Icon = $icon }
} catch { return [PSCustomObject]@{ IP = "-"; Icon = "🖧" } }
}
# --- WAN IP — cachowany co 5 minut
$script:__wanIP = $null
$script:__wanLastFetch = [DateTime]::MinValue
function Get-WanIP {
$now = Get-Date
if ($null -ne $script:__wanIP -and ($now - $script:__wanLastFetch).TotalMinutes -lt 5) {
return $script:__wanIP
}
try {
$ip = (Invoke-RestMethod -Uri "https://api4.my-ip.io/ip.json" -TimeoutSec 3).ip
$script:__wanIP = $ip
$script:__wanLastFetch = $now
return $ip
} catch {
if ($null -ne $script:__wanIP) { return $script:__wanIP }
return "-"
}
}
# --- Czas wykonania komendy (z historii PS)
function Format-Elapsed([TimeSpan]$ts) {
if ($ts.TotalMilliseconds -lt 1000) { return $null }
$parts = @()
if ($ts.Hours) { $parts += "$($ts.Hours)h" }
if ($ts.Minutes) { $parts += "$($ts.Minutes)m" }
if ($ts.Seconds) { $parts += "$($ts.Seconds)s" }
return ($parts -join ' ')
}
# --- PROMPT
function prompt {
$lastCmd = Get-History -Count 1
$elapsed = if ($lastCmd) {
$lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime
} else {
[TimeSpan]::Zero
}
$isAdmin = Test-IsAdmin
$colorMain = if ($isAdmin) { 'Red' } else { 'Green' }
$symbol = if ($isAdmin) { '# ' } else { '$ ' }
# Linia 1
$status = if ($?) { '✔' } else { '✘' }
$elapsedStr = Format-Elapsed $elapsed
Write-Host -NoNewline $status -ForegroundColor $colorMain
if ($elapsedStr) {
Write-Host -NoNewline " ⏱ $elapsedStr" -ForegroundColor DarkGray
}
Write-Host -NoNewline " 🕒 $(Get-Date -Format 'HH:mm:ss')" -ForegroundColor Blue
Write-Host -NoNewline " $env:USERNAME@$env:COMPUTERNAME" -ForegroundColor Cyan
if ($isAdmin) { Write-Host -NoNewline " 🛡️" -ForegroundColor Magenta }
Write-Host ""
# Linia 2
$path = Get-ShortPath
$lan = Get-LanIP
$wan = Get-WanIP
Write-Host -NoNewline "📁 $path" -ForegroundColor $colorMain
Write-Host -NoNewline " $($lan.Icon) $($lan.IP)" -ForegroundColor Yellow
Write-Host -NoNewline " 🌍 $wan" -ForegroundColor Yellow
Write-Host ""
Write-Host -NoNewline $symbol -ForegroundColor $colorMain
return " "
}
# --- PSReadLine (kompatybilny z PS 5.1 i PS 7)
try {
Set-PSReadLineOption -EditMode Windows -PredictionSource History -BellStyle None
} catch {
Set-PSReadLineOption -EditMode Windows -BellStyle None
}
# --- Reload profilu
function Reload-Profile {
. $PROFILE
Write-Host "✓ Profile reloaded" -ForegroundColor Green
}
function reload { Reload-Profile }
function rlp { Reload-Profile }
# --- Uruchom jako admin
function adm {
param([Parameter(ValueFromRemainingArguments)][string[]]$Command)
$pwsh = Get-Command pwsh -ErrorAction SilentlyContinue
$exe = if ($pwsh) { $pwsh.Source } else { (Get-Command powershell).Source }
if (-not $Command) {
Write-Host "Użycie: adm <polecenie>" -ForegroundColor Yellow
return
}
Start-Process $exe -ArgumentList "-NoProfile", "-Command", ($Command -join ' ') -Verb RunAs
}
Remember uin both to install font:
https://github.com/microsoft/cascadia-code/releases/download/v2407.24/CascadiaCode-2407.24.zip
just ttf type
PowerShell 7.x
# =========================================================
# PROMPT PS 7+ — dwuliniowy z LAN/WAN IP
# Linia 1: ✔/✘ 🕒 godzina user@host
# Linia 2: 📁 Rodzic\Bieżący 📶/🖧 LAN 🌍 WAN $/#
# =========================================================
try { $host.PrivateData.StartupBanner = "" } catch {}
# --- Admin?
function Test-IsAdmin {
try {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$p = [Security.Principal.WindowsPrincipal]::new($id)
return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
} catch { return $false }
}
# --- Rodzic\Bieżący
function Get-ShortPath {
$loc = (Get-Location).Path
try { $item = Get-Item -LiteralPath $loc -ErrorAction Stop } catch { return $loc }
if ($null -eq $item.Parent) { return $item.FullName }
return "$($item.Parent.Name)\$($item.Name)"
}
# --- LAN IP (📶 WiFi / 🖧 kabel)
function Get-LanIP {
try {
$excluded = @('Loopback', 'Tunnel')
$iface = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() |
Where-Object {
$_.OperationalStatus -eq 'Up' -and
$_.NetworkInterfaceType.ToString() -notin $excluded -and
$_.Name -notmatch 'WSL|Hyper-V|vEthernet|Loopback'
} |
Where-Object {
$null -ne ($_.GetIPProperties().UnicastAddresses |
Where-Object {
$_.Address.AddressFamily.ToString() -eq 'InterNetwork' -and
$_.Address.ToString() -notmatch '^169\.254'
} |
Select-Object -First 1)
} |
Select-Object -First 1
if (-not $iface) { return [PSCustomObject]@{ IP = "—"; Icon = "🖧" } }
$ip = $iface.GetIPProperties().UnicastAddresses |
Where-Object { $_.Address.AddressFamily.ToString() -eq 'InterNetwork' } |
Select-Object -First 1
$icon = if ($iface.NetworkInterfaceType.ToString() -eq 'Wireless80211') { "📶" } else { "🖧" }
return [PSCustomObject]@{ IP = $ip.Address.ToString(); Icon = $icon }
} catch { return [PSCustomObject]@{ IP = "—"; Icon = "🖧" } }
}
# --- WAN IP — cachowany co 5 minut
$script:__wanIP = $null
$script:__wanLastFetch = [DateTime]::MinValue
function Get-WanIP {
$now = Get-Date
if ($null -ne $script:__wanIP -and ($now - $script:__wanLastFetch).TotalMinutes -lt 5) {
return $script:__wanIP
}
try {
$ip = (Invoke-RestMethod -Uri "https://api4.my-ip.io/ip.json" -TimeoutSec 3).ip
$script:__wanIP = $ip
$script:__wanLastFetch = $now
return $ip
} catch {
return $script:__wanIP ?? "—"
}
}
# --- Czas wykonania komendy (z historii PS)
function Format-Elapsed([TimeSpan]$ts) {
if ($ts.TotalMilliseconds -lt 1000) { return $null }
$parts = @()
if ($ts.Hours) { $parts += "$($ts.Hours)h" }
if ($ts.Minutes) { $parts += "$($ts.Minutes)m" }
if ($ts.Seconds) { $parts += "$($ts.Seconds)s" }
return ($parts -join ' ')
}
# --- PROMPT
function prompt {
$lastCmd = Get-History -Count 1
$elapsed = if ($lastCmd) {
$lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime
} else {
[TimeSpan]::Zero
}
$isAdmin = Test-IsAdmin
$fg = if ($isAdmin) { $PSStyle.Foreground.Red } else { $PSStyle.Foreground.Green }
$fgTime = $PSStyle.Foreground.Blue
$fgUser = $PSStyle.Foreground.Cyan
$fgDim = $PSStyle.Foreground.BrightBlack
$fgNet = $PSStyle.Foreground.Yellow
$rst = $PSStyle.Reset
$bold = $PSStyle.Bold
# Linia 1
$status = if ($?) { "✔" } else { "✘" }
$elapsedStr = Format-Elapsed $elapsed
$elapsedSeg = if ($elapsedStr) { " $fgDim⏱ $elapsedStr$rst" } else { "" }
$shield = if ($isAdmin) { " 🛡️" } else { "" }
$line1 = "$fg$status$rst$elapsedSeg $fgTime🕒 $(Get-Date -Format 'HH:mm:ss')$rst $fgUser$env:USERNAME@$env:COMPUTERNAME$rst$shield"
# Linia 2
$path = Get-ShortPath
$lan = Get-LanIP
$wanIP = Get-WanIP
$symbol = if ($isAdmin) { "#" } else { "$" }
$line2 = "$fg$bold📁 $path$rst $fgNet$($lan.Icon) $($lan.IP)$rst $fgNet🌍 $wanIP$rst $fg$symbol$rst "
"$line1`n$line2"
}
# --- PSReadLine
Set-PSReadLineOption -EditMode Windows -PredictionSource History -PredictionViewStyle ListView -BellStyle None
# --- Reload profilu
function Reload-Profile { . $PROFILE; Write-Host "✓ Profile reloaded" -ForegroundColor Green }
function reload { Reload-Profile }
function rlp { Reload-Profile }
# --- Uruchom jako admin
function adm {
param([Parameter(ValueFromRemainingArguments)][string[]]$Command)
$exe = (Get-Command pwsh -ErrorAction SilentlyContinue)?.Source ?? (Get-Command powershell).Source
if (-not $Command) {
Write-Host "Użycie: adm <polecenie>" -ForegroundColor Yellow; return
}
Start-Process $exe -ArgumentList "-NoProfile", "-Command", ($Command -join ' ') -Verb RunAs
}
