diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-04-05 13:53:29 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-04-05 13:53:29 +0200 |
commit | 5d12ddb93e95b05eb0c53373d47b1407072e8d5b (patch) | |
tree | dd23982c13f5103f384144ba65351b644c9b9f20 /config/essentials/zsh | |
parent | 42874ddeaa72328187ee555bc95c209310e6910d (diff) |
fixed git aliases needing functions
Diffstat (limited to 'config/essentials/zsh')
-rw-r--r-- | config/essentials/zsh/functions.zsh | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/config/essentials/zsh/functions.zsh b/config/essentials/zsh/functions.zsh index 9d16c0d..189dd22 100644 --- a/config/essentials/zsh/functions.zsh +++ b/config/essentials/zsh/functions.zsh @@ -94,4 +94,38 @@ sgd () { test "$(parse_git_remote)" && echo "$PWD \e[0;32m*push/pull\e[0m" done - } +} + +# Git functions +# Returns current branch +function git_current_branch() +{ + command git rev-parse --git-dir &>/dev/null || return + git branch --show-current +} + +# Check if main exists and use instead of master +function git_main_branch() { + command git rev-parse --git-dir &>/dev/null || return + local ref + for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default}; do + if command git show-ref -q --verify $ref; then + echo ${ref:t} + return + fi + done + echo master +} + +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir &>/dev/null || return + local branch + for branch in dev devel development; do + if command git show-ref -q --verify refs/heads/$branch; then + echo $branch + return + fi + done + echo develop +} |