Skip to content

Instantly share code, notes, and snippets.

@trmcnvn
Last active November 7, 2019 12:34
Show Gist options
  • Save trmcnvn/61e02e907278bcffe3c626e04360a630 to your computer and use it in GitHub Desktop.
Save trmcnvn/61e02e907278bcffe3c626e04360a630 to your computer and use it in GitHub Desktop.
pshazz
try { Get-Command git -ea stop > $null } catch { return }
function pshazz:git-slim:init {
$git = $global:pshazz.theme.git
$dirty = $git.prompt_dirty
$unstaged = $git.prompt_unstaged
$staged = $git.prompt_staged
$stash = $git.prompt_stash
$untracked = $git.prompt_untracked
$push = $git.prompt_remote_push
$pull = $git.prompt_remote_pull
$same = $git.prompt_remote_same
# defaults
if(!$dirty) { $dirty = "*" }
if(!$unstaged) { $unstaged = "*" }
if(!$staged) { $staged = "+" }
if(!$stash) { $stash = "$" }
if(!$untracked) { $untracked = "%" }
if(!$push) { $push = ">" }
if(!$pull) { $pull = "<" }
if(!$same) { $same = "=" }
$global:pshazz.git = @{
prompt_dirty = $dirty;
prompt_unstaged = $unstaged;
prompt_staged = $staged;
prompt_stash = $stash;
prompt_untracked = $untracked;
prompt_remote_push = $push;
prompt_remote_pull = $pull;
prompt_remote_same = $same;
prompt_lbracket = $git.prompt_lbracket;
prompt_rbracket = $git.prompt_rbracket;
}
$global:pshazz.completions.git = resolve-path "$pluginDir\..\libexec\git-complete.ps1"
}
# Based on posh-git
function global:pshazz:git-slim:git_branch($git_dir) {
$r = ''; $b = ''; $c = ''
if (Test-Path $git_dir\rebase-merge\interactive) {
$r = '|REBASE-i'
$b = "$(Get-Content $git_dir\rebase-merge\head-name)"
} elseif (Test-Path $git_dir\rebase-merge) {
$r = '|REBASE-m'
$b = "$(Get-Content $git_dir\rebase-merge\head-name)"
} else {
if (Test-Path $git_dir\rebase-apply) {
if (Test-Path $git_dir\rebase-apply\rebasing) {
$r = '|REBASE'
} elseif (Test-Path $git_dir\rebase-apply\applying) {
$r = '|AM'
} else {
$r = '|AM/REBASE'
}
} elseif (Test-Path $git_dir\MERGE_HEAD) {
$r = '|MERGING'
} elseif (Test-Path $git_dir\CHERRY_PICK_HEAD) {
$r = '|CHERRY-PICKING'
} elseif (Test-Path $git_dir\BISECT_LOG) {
$r = '|BISECTING'
}
try { $b = git symbolic-ref HEAD } catch { }
if (-not $b) {
try { $b = git rev-parse --short HEAD } catch { }
}
}
if ('true' -eq $(git rev-parse --is-inside-git-dir 2>$null)) {
if ('true' -eq $(git rev-parse --is-bare-repository 2>$null)) {
$c = 'BARE:'
} else {
$b = 'GIT_DIR!'
}
}
return "$c$($b -replace 'refs/heads/','')$r"
}
function global:pshazz:git-slim:prompt {
$vars = $global:pshazz.prompt_vars
$git_root = pshazz_local_or_parent_path .git
if ($git_root) {
$vars.git_current_branch = ([char]0xe0a0);
$vars.yes_git = ([char]0xe0b0);
$vars.is_git = $true
$vars.git_branch = pshazz:git-slim:git_branch (Join-Path $git_root ".git")
try { $status = git status --porcelain } catch { }
if($status) {
$vars.git_dirty = $global:pshazz.git.prompt_dirty
}
} else {
$vars.no_git = ([char]0xe0b0);
}
}
{
"plugins": ["git-slim", "ssh"],
"prompt": [
["", "", "λ "],
["", "", "$path\\"],
["green", "", " $git_branch"],
["green", "", "$git_dirty"]
],
"git": {
"prompt_dirty": "*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment