mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-20 03:02:29 +01:00
added gitbranch function
This commit is contained in:
parent
75b6aa5c8f
commit
3340bf248a
1 changed files with 47 additions and 1 deletions
|
|
@ -73,7 +73,6 @@ prompt_git() {
|
||||||
local ref dirty mode repo_path
|
local ref dirty mode repo_path
|
||||||
repo_path=$(git rev-parse --git-dir 2>/dev/null)
|
repo_path=$(git rev-parse --git-dir 2>/dev/null)
|
||||||
|
|
||||||
source ~/gitbranch.sh
|
|
||||||
gitbranch;
|
gitbranch;
|
||||||
|
|
||||||
if [[ "$GITBRANCH" != "" ]]; then
|
if [[ "$GITBRANCH" != "" ]]; then
|
||||||
|
|
@ -87,6 +86,53 @@ prompt_dir() {
|
||||||
prompt_segment blue black '%~'
|
prompt_segment blue black '%~'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Fast method to get the current branch in git from https://gist.github.com/wolever/6525437
|
||||||
|
gitbranch() {
|
||||||
|
export GITBRANCH=""
|
||||||
|
|
||||||
|
local repo="${_GITBRANCH_LAST_REPO-}"
|
||||||
|
local gitdir=""
|
||||||
|
[[ ! -z "$repo" ]] && gitdir="$repo/.git"
|
||||||
|
|
||||||
|
# If we don't have a last seen git repo, or we are in a different directory
|
||||||
|
if [[ -z "$repo" || "$PWD" != "$repo"* || ! -e "$gitdir" ]]; then
|
||||||
|
local cur="$PWD"
|
||||||
|
while [[ ! -z "$cur" ]]; do
|
||||||
|
if [[ -e "$cur/.git" ]]; then
|
||||||
|
repo="$cur"
|
||||||
|
gitdir="$cur/.git"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
cur="${cur%/*}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$gitdir" ]]; then
|
||||||
|
unset _GITBRANCH_LAST_REPO
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
export _GITBRANCH_LAST_REPO="${repo}"
|
||||||
|
local head=""
|
||||||
|
local branch=""
|
||||||
|
read head < "$gitdir/HEAD"
|
||||||
|
case "$head" in
|
||||||
|
ref:*)
|
||||||
|
branch="${head##*/}"
|
||||||
|
;;
|
||||||
|
"")
|
||||||
|
branch=""
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
branch="d:${head:0:7}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
if [[ -z "$branch" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
export GITBRANCH="$branch"
|
||||||
|
}
|
||||||
|
|
||||||
# Status:
|
# Status:
|
||||||
# - was there an error
|
# - was there an error
|
||||||
# - am I root
|
# - am I root
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue