From 471d336cc4c0076c1bb5a35a5731bd69f8ea553c Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Mon, 10 Aug 2026 11:46:02 +0100 Subject: [PATCH] Add copy current git branch name binding --- build/build.plugin.zsh | 4 ++-- utilities/utilities.plugin.zsh | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build/build.plugin.zsh b/build/build.plugin.zsh index 48149d5..8d51271 100644 --- a/build/build.plugin.zsh +++ b/build/build.plugin.zsh @@ -133,9 +133,9 @@ EOF eval build fi - # Bind C-B to fuzzy find & complete cmake variables. + # Bind C-X C-V to fuzzy find & complete cmake variables. zle -N .build-var - bindkey '^B' .build-var + bindkey '^X^V' .build-var } # Build then run a target residing in `~build/bin`. diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh index e7cf931..5f79651 100644 --- a/utilities/utilities.plugin.zsh +++ b/utilities/utilities.plugin.zsh @@ -203,3 +203,18 @@ function .fzf-history-search() { } zle -N .fzf-history-search bindkey '^R' .fzf-history-search + +# Copy the branch name checked out in the current worktree to the clipboard, +# falling back to the abbreviated commit when HEAD is detached. +function .copy-git-branch() { + local branch + branch=$(git symbolic-ref --quiet --short HEAD 2>/dev/null) || + branch=$(git rev-parse --short HEAD 2>/dev/null) + if [[ -n "$branch" ]]; then + print -rn -- "$branch" | copy + else + zle -M "not a git worktree" + fi +} +zle -N .copy-git-branch +bindkey -p '^X^B' .copy-git-branch