From 44e74030d99f915e2e971aa44b20a375fa2a383e Mon Sep 17 00:00:00 2001 From: Todd Hogarth Date: Thu, 20 Nov 2025 07:19:52 -0500 Subject: [PATCH 1/5] Improves shell prompt with git and nvm info Enhances the shell prompt to display Git branch and status information, as well as the currently active Node.js version managed by NVM. - Sources `.git-prompt-support` to provide git status in the prompt. - Modifies `gitlogp` to allow reverse chronological listing. - Uses helper functions to obtain the basename of the nvm symlink target and parent directory to support both Windows and Linux environments. - Changes git status indicators from parenthesis to curly braces. --- .git-prompt-support | 5 +-- src/bash.sh | 2 ++ src/functions.sh | 84 ++++++++++++++++++++++++++++++--------------- src/prompt.sh | 34 +++++++++++++++--- 4 files changed, 92 insertions(+), 33 deletions(-) diff --git a/.git-prompt-support b/.git-prompt-support index dcbf30e..c9f8941 100644 --- a/.git-prompt-support +++ b/.git-prompt-support @@ -1,3 +1,4 @@ +#!/bin/env bash # bash/zsh git prompt support # # Copyright (C) 2006,2007 Shawn O. Pearce @@ -321,11 +322,11 @@ __git_sequencer_status () elif __git_eread "$g/sequencer/todo" todo then case "$todo" in - p[\ \ ]|pick[\ \ ]*) + p[[:space:]]|pick[[:space:]]*) r="|CHERRY-PICKING" return 0 ;; - revert[\ \ ]*) + revert[[:space:]]*) r="|REVERTING" return 0 ;; diff --git a/src/bash.sh b/src/bash.sh index 1296667..ba3d393 100644 --- a/src/bash.sh +++ b/src/bash.sh @@ -14,6 +14,8 @@ shopt -s histverify # Git completion support # shellcheck disable=SC1091 source "$DEVROOT/dev-tools/.git-completion-support" +# shellcheck disable=SC1091 +source "$DEVROOT/dev-tools/.git-prompt-support" # Command Prompt # shellcheck disable=SC1091 diff --git a/src/functions.sh b/src/functions.sh index bd0ceb8..72ae4f6 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -92,11 +92,34 @@ gitlog() { ' | column -ts '|' } - +# pretty one line git log of current repository with merge and side branch indicators gitlogp() { - entries=$1 - branch="$2" - [ -n "$entries" ] && entries="-${entries#-}" + entries="" + branch="" + reverseFlag=0 + + # parse named args + while [ $# -gt 0 ]; do + case "$1" in + -n|--entries) + entries="-$2" + shift 2 + ;; + -b|--branch) + branch="$2" + shift 2 + ;; + -r|--reverse) + reverseFlag=1 + shift + ;; + *) + echo "Unknown option: $1" + echo "Usage: gitlog [-n N] [-b branch] [-r]" + return 1 + ;; + esac + done fmt='%h|%p|%cd|%an|%(describe:tags)|%s' datearg="--date=format:%m-%d-%y %H:%M" @@ -105,7 +128,7 @@ gitlogp() { git log "$branch" --format="$fmt" "$datearg" $entries else git log --format="$fmt" "$datearg" $entries - fi | awk -F'|' ' + fi | awk -F'|' -v reverseFlag=$reverseFlag ' { commit=$1 parents=$2 @@ -123,18 +146,12 @@ gitlogp() { n=split(parents, arr, " ") parentCount[commit]=n + for (i=1; i<=n; i++) if (arr[i] != "") parentOf[commit]=parentOf[commit] " " arr[i] - for (i=1; i<=n; i++) { - if (arr[i] != "") parentOf[commit]=parentOf[commit] " " arr[i] - } - - # mark the *second parent* of merges - if (n > 1) { - markBranch[arr[2]]=1 - } + if (n > 1) markBranch[arr[2]]=1 } END { - # propagate [side] marks backwards + # propagate [side] changed=1 while (changed) { changed=0 @@ -150,20 +167,33 @@ gitlogp() { } } - for (i=1; i<=NR; i++) { - c=order[i] - - # decide marker - if (parentCount[c] > 1) { - flag="[merge]" - } else if (c in markBranch) { - flag="[side]" - } else { - flag=" " + # decide iteration order + if (reverseFlag) { + for (i=NR; i>=1; i--) { + c=order[i] + if (parentCount[c] > 1) { + flag="[merge]" + } else if (c in markBranch) { + flag="[side]" + } else { + flag=" " + } + printf "%-8s %-7s | %-20s | %-14s | %-15s | %-25s | %s\n", \ + c, flag, parentsOf[c], dateOf[c], authorOf[c], tagOf[c], subjectOf[c] + } + } else { + for (i=1; i<=NR; i++) { + c=order[i] + if (parentCount[c] > 1) { + flag="[merge]" + } else if (c in markBranch) { + flag="[side]" + } else { + flag=" " + } + printf "%-8s %-7s | %-20s | %-14s | %-15s | %-25s | %s\n", \ + c, flag, parentsOf[c], dateOf[c], authorOf[c], tagOf[c], subjectOf[c] } - - printf "%-8s %-7s %-20s %-14s %-15s %-25s %s\n", \ - c, flag, parentsOf[c], dateOf[c], authorOf[c], tagOf[c], subjectOf[c] } } ' diff --git a/src/prompt.sh b/src/prompt.sh index bc8ff63..b667862 100644 --- a/src/prompt.sh +++ b/src/prompt.sh @@ -30,16 +30,42 @@ Time12h="\T" PathShort="\w" Date="\d" +# obtain the folder name of the selected node version (from nvm symlink) +get_symlink_basename() { + # Check if NVM_SYMLINK is set + if [ -z "$NVM_SYMLINK" ]; then + echo "NVM_SYMLINK is not set." + return 1 + fi + + # Get the actual target path of the symlink + local target + target=$(readlink "$NVM_SYMLINK") + + # Extract the basename of the folder + local version="${target##*/}" # Get the last part after the last '/' + + # Echo the extracted version + echo "$version" +} + +# Helper: get parent directory name (portable) +get_parent_dirname() { + local dir + dir="${NVM_BIN%/*}" + echo "${dir##*/}" +} + # test if NVM_SYMLINK exists if [[ -L "$NVM_SYMLINK" ]]; then # prompt for use in windows echo " -- windows prompt" - export PS1=$Cyan$Time12h$Color_Off$Purple' <$(basename $(readlink "$NVM_SYMLINK"))>'$Color_Off'$(git branch &>/dev/null;\ + export PS1=$Cyan$Time12h$Color_Off$Purple' <$(get_symlink_basename)>'$Color_Off'$(git branch &>/dev/null;\ if [ $? -eq 0 ]; then \ echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \ if [ "$?" -eq "0" ]; then \ # Clean repository - nothing to commit - echo "'$Green'"$(__git_ps1 " (%s)"); \ + echo "'$Green'"$(__git_ps1 " {%s}"); \ else \ # Changes to working tree echo "'$Red'"$(__git_ps1 " {%s}"); \ @@ -54,12 +80,12 @@ fi if [ -d "$NVM_DIR" ]; then echo " -- linux prompt" # prompt for use in linux - export PS1=$Cyan$Time12h$Color_Off$Purple' <$(basename $(dirname "$NVM_BIN"))>'$Color_Off'$(git branch &>/dev/null;\ + export PS1=$Cyan$Time12h$Color_Off$Purple' <$(get_parent_dirname)>'$Color_Off'$(git branch &>/dev/null;\ if [ $? -eq 0 ]; then \ echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \ if [ "$?" -eq "0" ]; then \ # Clean repository - nothing to commit - echo "'$Green'"$(__git_ps1 " (%s)"); \ + echo "'$Green'"$(__git_ps1 " {%s}"); \ else \ # Changes to working tree echo "'$Red'"$(__git_ps1 " {%s}"); \ From 0f444e00141f0f334a0688548ad14bf7d1519946 Mon Sep 17 00:00:00 2001 From: Todd Hogarth Date: Thu, 20 Nov 2025 07:39:45 -0500 Subject: [PATCH 2/5] Update src/functions.sh Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.sh b/src/functions.sh index 72ae4f6..428491a 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -115,7 +115,7 @@ gitlogp() { ;; *) echo "Unknown option: $1" - echo "Usage: gitlog [-n N] [-b branch] [-r]" + echo "Usage: gitlogp [-n N] [-b branch] [-r]" return 1 ;; esac From 245b63c9089063b484d98002efa6bc6ccb3b3e37 Mon Sep 17 00:00:00 2001 From: Todd Hogarth Date: Thu, 20 Nov 2025 07:40:45 -0500 Subject: [PATCH 3/5] Update .git-prompt-support Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .git-prompt-support | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.git-prompt-support b/.git-prompt-support index c9f8941..797ab1f 100644 --- a/.git-prompt-support +++ b/.git-prompt-support @@ -1,4 +1,4 @@ -#!/bin/env bash +#!/usr/bin/env bash # bash/zsh git prompt support # # Copyright (C) 2006,2007 Shawn O. Pearce From 3b5f8c0f2af455a4abc0a499d2abc427a2cd3d2c Mon Sep 17 00:00:00 2001 From: Todd Hogarth Date: Thu, 20 Nov 2025 08:09:10 -0500 Subject: [PATCH 4/5] Update src/prompt.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/prompt.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/prompt.sh b/src/prompt.sh index b667862..3dba85c 100644 --- a/src/prompt.sh +++ b/src/prompt.sh @@ -34,8 +34,7 @@ Date="\d" get_symlink_basename() { # Check if NVM_SYMLINK is set if [ -z "$NVM_SYMLINK" ]; then - echo "NVM_SYMLINK is not set." - return 1 + return fi # Get the actual target path of the symlink From bfdf53d289b36867e12f4b9842daab9ff50c2bf6 Mon Sep 17 00:00:00 2001 From: Todd Hogarth Date: Thu, 20 Nov 2025 08:18:22 -0500 Subject: [PATCH 5/5] Removes unused code Removes an unused loop that was iterating over parent commits. The loop was not contributing to the functionality of the script. --- src/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.sh b/src/functions.sh index 428491a..d8b0857 100644 --- a/src/functions.sh +++ b/src/functions.sh @@ -146,7 +146,7 @@ gitlogp() { n=split(parents, arr, " ") parentCount[commit]=n - for (i=1; i<=n; i++) if (arr[i] != "") parentOf[commit]=parentOf[commit] " " arr[i] + if (n > 1) markBranch[arr[2]]=1 }