dotfiles/.config/fish/conf.d/30-git.fish
punkfairie 5af5389117
feat(git): Move git aliases to git
Also fixed the wrongly named .gitconfig -> config, and standardized
naming among all subfiles.

All git aliases are managed by git now - to allow wrappers to access the
same aliases (e.g. dotfiles).
2024-02-27 20:54:41 -08:00

51 lines
1.3 KiB
Fish

#!/usr/bin/env fish
abbr -a g --position command git
abbr -a d --position command dotfiles
################################################################################
# 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
end
echo develop
return 1
end
function git_main_branch
command git rev-parse --git-dir &>/dev/null || return
set -l ref
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
end
echo main
return 1
end
function git_current_branch
set -l ref (git symbolic-ref --quiet HEAD 2>/dev/null)
set -l ret $status
if [ $ret -ne 0 ]
[ $ret -eq 128 ] && return # no git repo
set ref (git rev-parse --short HEAD 2>/dev/null) || return
end
echo (string replace "refs/heads/" "" $ref)
end