diff --git a/plugins/git/README.md b/plugins/git/README.md index 46c36548a..e31ba3b0c 100644 --- a/plugins/git/README.md +++ b/plugins/git/README.md @@ -254,6 +254,7 @@ receive further support. | `git_current_user_name` | Returns the `user.name` config value (Lives in `lib/git.zsh`) | | `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 | +| `gbcopy` | Copies current branch name to clipboard | | `grename ` | Renames branch `` to ``, including on the origin remote | | `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 16568f222..ed1121d51 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -49,6 +49,17 @@ function git_main_branch() { return 1 } +function gbcopy() { + # Check if we are in a Git repository + command git rev-parse --git-dir &>/dev/null || return + + local branch + branch="$(command git symbolic-ref --short -q HEAD)" || return + [[ -n "$branch" ]] || return 1 + + print -rn -- "$branch" | clipcopy +} + function grename() { if [[ -z "$1" || -z "$2" ]]; then echo "Usage: $0 old_branch new_branch"