2024-04-14 18:41:15 -07:00
|
|
|
#!/usr/bin/env fish
|
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
if command -v git &>/dev/null
|
|
|
|
abbr -a g --position command git
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
# Functions #
|
|
|
|
############################################################################
|
|
|
|
|
|
|
|
function git_develop_branch
|
|
|
|
command git rev-parse --git-dir &>/dev/null || return
|
|
|
|
set -l branch
|
|
|
|
|
|
|
|
for branch in dev devel develop development
|
|
|
|
if command git show-ref -q --verify refs/heads/$branch
|
|
|
|
echo $branch
|
|
|
|
return 0
|
|
|
|
end
|
2024-04-14 18:41:15 -07:00
|
|
|
end
|
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
echo develop
|
|
|
|
return 1
|
|
|
|
end
|
2024-04-14 18:41:15 -07:00
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
function git_main_branch
|
|
|
|
command git rev-parse --git-dir &>/dev/null || return
|
|
|
|
set -l ref
|
2024-04-14 18:41:15 -07:00
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
for ref in
|
|
|
|
refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,master}
|
|
|
|
if command git show-ref -q --verify $ref
|
|
|
|
echo (basename $ref)
|
|
|
|
return 0
|
|
|
|
end
|
2024-04-14 18:41:15 -07:00
|
|
|
end
|
2024-10-02 21:01:45 -07:00
|
|
|
|
|
|
|
echo main
|
|
|
|
return 1
|
2024-04-14 18:41:15 -07:00
|
|
|
end
|
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
function git_current_branch
|
|
|
|
set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null)
|
|
|
|
set -l ret $status
|
2024-04-14 18:41:15 -07:00
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
if [ $ret -ne 0 ]
|
|
|
|
[ $ret -eq 128 ] && return # no git repo
|
|
|
|
set ref (git rev-parse --short HEAD 2>/dev/null) || return
|
|
|
|
end
|
2024-04-14 18:41:15 -07:00
|
|
|
|
2024-10-02 21:01:45 -07:00
|
|
|
echo (string replace "refs/heads/" "" $ref)
|
2024-04-14 18:41:15 -07:00
|
|
|
end
|
|
|
|
end
|