Skip to content

Instantly share code, notes, and snippets.

@cmargroff
Last active September 21, 2022 13:34
Show Gist options
  • Save cmargroff/dac28ed735d08e3f73725d6b55feb17e to your computer and use it in GitHub Desktop.
Save cmargroff/dac28ed735d08e3f73725d6b55feb17e to your computer and use it in GitHub Desktop.
Agnoster for Powershell [WIP]
# base code
Set-Alias ll ls
Set-Alias touch New-Item
Del alias:cd -Force
Set-Alias cd push-location -Force
# theme code
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
$e = [char]0x1b
$reset = "$e[0m"
$SEGMENT_SEPARATOR = [char]0xe0b0
$CURRENT_BG='NONE'
$F = @{
NONE = "$e[0m";
black = "$e[30m";
red = "$e[31m";
green = "$e[32m";
yellow = "$e[33m";
blue = "$e[34m";
magenta = "$e[35m";
cyan = "$e[36m";
white = "$e[37m";
}
$K = @{
NONE = "$e[0m";
black = "$e[40m";
red = "$e[41m";
green = "$e[42m";
yellow = "$e[43m";
blue = "$e[44m";
magenta = "$e[45m";
cyan = "$e[46m";
white = "$e[47m";
}
# $batIcon = `u{1F50B}
$batIcon = [System.Char]::ConvertFromUtf32([System.Convert]::toInt32("1F50B",16))
function segment {
param (
$1,
$2,
$text
)
if($1 -ne $null) {
$bg = $K[$1]
} else {
$bg = $K.black
}
if($2 -ne $null) {
$fg = $F[$2]
} else {
$fg = $F.white
}
if($CURRENT_BG -ne 'NONE' -And $1 -ne $CURRENT_BG){
echo "$bg$($f[$CURRENT_BG])$SEGMENT_SEPARATOR$fg";
} else {
echo "$bg$fg ";
}
$script:CURRENT_BG=$1
if($text -ne $null){
echo "$text ";
}
}
function prompt_char {
segment green black $([char]0x0394);
}
function prompt_power {
$battery = (Get-WmiObject win32_battery)
if($battery.Availability -eq '3' -And $battery.BatteryStatus -eq '1') {
segment green white "$batIcon $($battery.EstimatedChargeRemaining)%";
}
}
function prompt_context {
segment black white "$env:UserName@$env:ComputerName";
}
function prompt_dir {
segment blue black "$(pwd)";
}
function prompt_git {
if((Get-Command git -errorAction SilentlyContinue) -And "$(git rev-parse --is-inside-work-tree)" -eq "true") {
$ref = $(git rev-parse --abbrev-ref HEAD) + " $([char]0x21aa) $(git rev-parse --short HEAD)"
segment yellow black "$ref"
}
}
function prompt_end {
if($CURRENT_BG -ne $null) {
echo "$($F[$CURRENT_BG])$($K.black)$SEGMENT_SEPARATOR"
}
echo "$($K.black)$($F.white)";
$CURRENT_BG = "NONE"
echo $reset
}
function prompt {
"$(prompt_char)$(prompt_power)$(prompt_context)$(prompt_dir)$(prompt_git)$(prompt_end)"
}
# need to remove defined functions
Clear-Variable e
Clear-Variable reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment