Add copy current git branch name binding

This commit is contained in:
2026-08-10 11:46:02 +01:00
parent c1293b1914
commit 471d336cc4
2 changed files with 17 additions and 2 deletions

View File

@@ -133,9 +133,9 @@ EOF
eval build eval build
fi 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 zle -N .build-var
bindkey '^B' .build-var bindkey '^X^V' .build-var
} }
# Build then run a target residing in `~build/bin`. # Build then run a target residing in `~build/bin`.

View File

@@ -203,3 +203,18 @@ function .fzf-history-search() {
} }
zle -N .fzf-history-search zle -N .fzf-history-search
bindkey '^R' .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