replicate gitstatus default prompt

This commit is contained in:
Ray Elliott 2025-09-30 19:35:43 +01:00
parent ac38a9302e
commit 2419a843a3
1 changed files with 63 additions and 1 deletions

64
bashrc
View File

@ -102,7 +102,69 @@ function show_date() {
export HISTCONTROL=ignoreboth:erasedups
[ -f "$HOME/.config/bash/gitstatus/gitstatus.prompt.sh" ] && . "$HOME/.config/bash/gitstatus/gitstatus.prompt.sh"
# Load gitstatus plugin for low-level API access
[ -f "$HOME/.config/bash/gitstatus/gitstatus.plugin.sh" ] && . "$HOME/.config/bash/gitstatus/gitstatus.plugin.sh"
# Custom gitstatus prompt function (replicates default behavior with customizations)
function my_gitstatus_prompt_update() {
GITSTATUS_PROMPT=""
gitstatus_query || return 1 # error
[[ "$VCS_STATUS_RESULT" == ok-sync ]] || return 0 # not a git repo
local reset=$'\001\e[0m\002' # no color
local clean=$'\001\e[38;5;076m\002' # green foreground
local untracked=$'\001\e[38;5;014m\002' # teal foreground
local modified=$'\001\e[38;5;011m\002' # yellow foreground
local conflicted=$'\001\e[38;5;196m\002' # red foreground
local p
# Branch name, tag or commit
local where
if [[ -n "$VCS_STATUS_LOCAL_BRANCH" ]]; then
where="$VCS_STATUS_LOCAL_BRANCH"
elif [[ -n "$VCS_STATUS_TAG" ]]; then
p+="${reset}#"
where="$VCS_STATUS_TAG"
else
p+="${reset}@"
where="${VCS_STATUS_COMMIT:0:8}"
fi
# Truncate long branch names and tags
(( ${#where} > 32 )) && where="${where:0:12}${where: -12}"
p+="${clean}${where}"
# Remote tracking status
(( VCS_STATUS_COMMITS_BEHIND )) && p+=" ${clean}${VCS_STATUS_COMMITS_BEHIND}"
(( VCS_STATUS_COMMITS_AHEAD && !VCS_STATUS_COMMITS_BEHIND )) && p+=" "
(( VCS_STATUS_COMMITS_AHEAD )) && p+="${clean}${VCS_STATUS_COMMITS_AHEAD}"
# Push remote status
(( VCS_STATUS_PUSH_COMMITS_BEHIND )) && p+=" ${clean}${VCS_STATUS_PUSH_COMMITS_BEHIND}"
(( VCS_STATUS_PUSH_COMMITS_AHEAD && !VCS_STATUS_PUSH_COMMITS_BEHIND )) && p+=" "
(( VCS_STATUS_PUSH_COMMITS_AHEAD )) && p+="${clean}${VCS_STATUS_PUSH_COMMITS_AHEAD}"
# CUSTOM: Stashes with "stash:" prefix instead of "*"
(( VCS_STATUS_STASHES )) && p+=" ${clean}stash:${VCS_STATUS_STASHES}"
# Repository state and file counts (default behavior)
[[ -n "$VCS_STATUS_ACTION" ]] && p+=" ${conflicted}${VCS_STATUS_ACTION}"
(( VCS_STATUS_NUM_CONFLICTED )) && p+=" ${conflicted}~${VCS_STATUS_NUM_CONFLICTED}"
(( VCS_STATUS_NUM_STAGED )) && p+=" ${modified}+${VCS_STATUS_NUM_STAGED}"
(( VCS_STATUS_NUM_UNSTAGED )) && p+=" ${modified}!${VCS_STATUS_NUM_UNSTAGED}"
(( VCS_STATUS_NUM_UNTRACKED )) && p+=" ${untracked}?${VCS_STATUS_NUM_UNTRACKED}"
GITSTATUS_PROMPT="${p}${reset}"
}
# Start gitstatusd and set up prompt command
gitstatus_stop && gitstatus_start -s -1 -u -1 -c -1 -d -1
PROMPT_COMMAND=my_gitstatus_prompt_update
shopt -s promptvars
# Set PS1 with time, user@host, directory, git status, and command line
PS1='\t \[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w\[\033[00m\]${GITSTATUS_PROMPT:+ $GITSTATUS_PROMPT}\n\[\033[01;$((31+!$?))m\]\$\[\033[00m\] \[\e]0;\u@\h: \w\a\]'
# If there are multiple matches for completion, Tab should cycle through them