mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
23 lines
514 B
Bash
23 lines
514 B
Bash
#
|
|
# Bash Helpers
|
|
#
|
|
|
|
function find_git_branch {
|
|
local dir=. head
|
|
until [ "$dir" -ef / ]; do
|
|
if [ -f "$dir/.git/HEAD" ]; then
|
|
head=$(< "$dir/.git/HEAD")
|
|
if [[ $head == ref:\ refs/heads/* ]]; then
|
|
git_branch=" (${head#*/*/})"
|
|
elif [[ $head != '' ]]; then
|
|
git_branch=' (detached)'
|
|
else
|
|
git_branch=' (unknown)'
|
|
fi
|
|
return
|
|
fi
|
|
dir="../$dir"
|
|
done
|
|
git_branch=''
|
|
}
|