From 816b94f41cba63c0f5a73d72cb27a17cb5ed94b1 Mon Sep 17 00:00:00 2001 From: yoshibase Date: Fri, 24 Jul 2026 21:14:05 -0700 Subject: [PATCH] Add gcbc helper to copy current git branch name Use the existing cross-platform clipcopy helper and report detached HEADs instead of copying an empty value. Fixes #13843 --- plugins/git/README.md | 1 + plugins/git/git.plugin.zsh | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/plugins/git/README.md b/plugins/git/README.md index c0a651375..7511adc44 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -255,6 +255,7 @@ receive further support. | `git_develop_branch` | Returns the name of the “development” branch: `dev`, `devel`, `development` if they exist, `develop` otherwise | | `git_main_branch` | Returns the name of the main branch: `main` if it exists, `master` otherwise | | `grename ` | Renames branch `` to ``, including on the origin remote | +| `gcbc` | Copies the current branch name to the system clipboard (uses `clipcopy`) | | `gbda` | Deletes all merged branches | | `gbds` | Deletes all squash-merged branches (**Note: performance degrades with number of branches**) | diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 9ef60d69a..a4e84080c 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -159,6 +159,14 @@ alias gbg='LANG=C git branch -vv | grep ": gone\]"' alias gco='git checkout' alias gcor='git checkout --recurse-submodules' alias gcb='git checkout -b' +function gcbc() { + local branch=$(git branch --show-current 2>/dev/null) || return + if [[ -z "$branch" ]]; then + print -u2 "gcbc: not on a branch" + return 1 + fi + print -rn -- "$branch" | clipcopy +} alias gcB='git checkout -B' alias gcd='git checkout $(git_develop_branch)' alias gcm='git checkout $(git_main_branch)'