This commit is contained in:
Ray Elliott 2025-09-30 19:55:54 +01:00
parent 2419a843a3
commit ee354503f2
2 changed files with 67 additions and 61 deletions

63
bashrc
View File

@ -102,67 +102,8 @@ function show_date() {
export HISTCONTROL=ignoreboth:erasedups
# 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
# Load custom gitstatus configuration
[ -f "$HOME/.config/bash/gitstatus-custom.sh" ] && . "$HOME/.config/bash/gitstatus-custom.sh"
# 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\]'

65
gitstatus-custom.sh Normal file
View File

@ -0,0 +1,65 @@
#!/bin/bash
# Custom gitstatus configuration with API-based prompt
# Source this file from bashrc for git status in prompt
# 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 green=$'\001\e[38;5;076m\002' # green - clean branch name
local blue=$'\001\e[38;5;014m\002' # blue - informational (untracked)
local yellow=$'\001\e[38;5;011m\002' # yellow - action pending (staged, behind/ahead)
local red=$'\001\e[38;5;196m\002' # red - urgent attention (conflicts, merge)
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+="${green}${where}"
# Remote tracking status (yellow - action pending)
(( VCS_STATUS_COMMITS_BEHIND )) && p+=" ${yellow}behind:${VCS_STATUS_COMMITS_BEHIND}"
(( VCS_STATUS_COMMITS_AHEAD && !VCS_STATUS_COMMITS_BEHIND )) && p+=" "
(( VCS_STATUS_COMMITS_AHEAD )) && p+="${yellow}ahead:${VCS_STATUS_COMMITS_AHEAD}"
# Push remote status (yellow - action pending)
(( VCS_STATUS_PUSH_COMMITS_BEHIND )) && p+=" ${yellow}push-behind:${VCS_STATUS_PUSH_COMMITS_BEHIND}"
(( VCS_STATUS_PUSH_COMMITS_AHEAD && !VCS_STATUS_PUSH_COMMITS_BEHIND )) && p+=" "
(( VCS_STATUS_PUSH_COMMITS_AHEAD )) && p+="${yellow}push-ahead:${VCS_STATUS_PUSH_COMMITS_AHEAD}"
# CUSTOM: Stashes with "stash:" prefix instead of "*"
(( VCS_STATUS_STASHES )) && p+=" ${reset}stashed:${VCS_STATUS_STASHES}"
# Repository state and file counts (descriptive labels)
[[ -n "$VCS_STATUS_ACTION" ]] && p+=" ${red}${VCS_STATUS_ACTION}"
(( VCS_STATUS_NUM_CONFLICTED )) && p+=" ${red}conflicts:${VCS_STATUS_NUM_CONFLICTED}"
(( VCS_STATUS_NUM_STAGED )) && p+=" ${yellow}staged:${VCS_STATUS_NUM_STAGED}"
(( VCS_STATUS_NUM_UNSTAGED )) && p+=" ${yellow}modified:${VCS_STATUS_NUM_UNSTAGED}"
(( VCS_STATUS_NUM_UNTRACKED )) && p+=" ${blue}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