diff --git a/.git-prompt-support b/.git-prompt-support index dcbf30e..797ab1f 100644 --- a/.git-prompt-support +++ b/.git-prompt-support @@ -1,3 +1,4 @@ +#!/usr/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..d8b0857 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: 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" @@ -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 @@ -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 @@ -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..3dba85c 100644 --- a/src/prompt.sh +++ b/src/prompt.sh @@ -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}"); \ @@ -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}"); \