From ee354503f2b8f6309431ffe7c08fc4c4b9f8cc8e Mon Sep 17 00:00:00 2001 From: ray Date: Tue, 30 Sep 2025 19:55:54 +0100 Subject: [PATCH] update --- bashrc | 63 ++----------------------------------------- gitstatus-custom.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 gitstatus-custom.sh diff --git a/bashrc b/bashrc index 39f7026..120c462 100644 --- a/bashrc +++ b/bashrc @@ -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\]' diff --git a/gitstatus-custom.sh b/gitstatus-custom.sh new file mode 100644 index 0000000..b4bfded --- /dev/null +++ b/gitstatus-custom.sh @@ -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 \ No newline at end of file