From 61a89ac1cbc0d19208de305ce4aca578e33ab9fd Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Fri, 24 Oct 2025 13:18:33 -0700 Subject: [PATCH] DRY up branchname definition --- git-recent | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/git-recent b/git-recent index 0ee5b13..71ab1d7 100755 --- a/git-recent +++ b/git-recent @@ -29,20 +29,22 @@ fi # Colorized hash, author, date, then commit subject followed by commit message body (wrapped and indented). commits_format="%C(red bold)%h %C(bold blue)%an %C(bold green)%ad %Creset%s%w(0,4,4)%+b%w(0,0,0)" -# commits_format='%h (%>(16)%ad %an) %s%w(0,4,4)%+b%w(0,0,0)' + # The HEAD of the primary branch (eg main or master or w/e), for diffing. # TODO: some branch mgmt approaches don't work well with this. And may prefer `git log --pretty=format:%H --merges -n 1`. See https://github.com/paulirish/git-recent/issues/28 diff_base=$(cat $(git rev-parse --show-cdup).git/refs/remotes/origin/HEAD | awk '{print $2}') -# the cut drops anything after the branch name, like the Chromium link. These commands need to work in all shells (bash, fish, etc) -uniqcommits_cmd="git log --date=human --color=always --format='$commits_format' --no-merges $diff_base..\$(echo {1} | cut -d' ' -f1)" -diffbranch_cmd="git diff --color=always $diff_base...\$(echo {1} | cut -d' ' -f1)" +# Extract branch name (without any trailing text, like the Chromium link) +define_branchname="branchname=\\\$(echo {1} | cut -d' ' -f1)" +uniqcommits_cmd="sh -c \"$define_branchname; git log --date=human --color=always --format='$commits_format' --no-merges $diff_base..\\\$branchname\"" # Progressive enhancement if you have delta or diff-so-fancy -if command -v delta >/dev/null 2>&1; then - diffbranch_cmd="$diffbranch_cmd | delta" +if command -v deltaz >/dev/null 2>&1; then + diffbranch_cmd="sh -c \"$define_branchname; git diff --color=always $diff_base...\\\$branchname | delta\"" elif command -v diff-so-fancy >/dev/null 2>&1; then - diffbranch_cmd="$diffbranch_cmd | diff-so-fancy" + diffbranch_cmd="sh -c \"$define_branchname; git diff --color=always $diff_base...\\\$branchname | diff-so-fancy\"" +else + diffbranch_cmd="sh -c \"$define_branchname; git diff --color=always $diff_base...\\\$branchname\"" fi # Copy to clipboard, variants for mac/linux @@ -73,7 +75,7 @@ NC='\033[0m' # No Color # - https://github.com/junegunn/fzf/wiki/Examples-(fish)#git # - https://github.com/junegunn/fzf-git.sh (intense.) -# If there's a GIT_RECENT_QUERY environment variable, use it for non-interactive filtering. (Primarily added for testing.) +# If there's a GIT_RECENT_QUERY environment variable, use it for non-interactive filtering. (Primarily added for testing: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/g/git-recent.rb#L41-L46) filterarg=${GIT_RECENT_QUERY:+"--filter=$GIT_RECENT_QUERY"} # Chromium hackers may want reference to their relevant CL.