Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .git-prompt-support
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# bash/zsh git prompt support
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
Expand Down Expand Up @@ -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
;;
Expand Down
2 changes: 2 additions & 0 deletions src/bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 56 additions & 26 deletions src/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: gitlogp [-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"
Expand All @@ -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
Expand All @@ -124,17 +147,11 @@ gitlogp() {
n=split(parents, arr, " ")
parentCount[commit]=n

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
Expand All @@ -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=" "
Comment on lines +179 to +192
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's inconsistent spacing in the flag field formatting. In the reverse block, the empty flag uses 7 spaces " " (line 179), while in the non-reverse block, it also uses 7 spaces " " (line 192). However, the original code used 6 spaces " ". This inconsistency should be addressed for uniform output alignment.

Copilot uses AI. Check for mistakes.
}
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]
}
}
'
Expand Down
33 changes: 29 additions & 4 deletions src/prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,41 @@ 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
return
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}"); \
Expand All @@ -54,12 +79,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}"); \
Expand Down
Loading