Add copy current git branch name binding
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user