mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
Git Current Remote
Make function definitions consistent. Copy current_branch from plugin and rename to git_current_branch. Exchange usage of current_branch with git_current_branch. Add helper function to get the current branch's remote. Update git_prompts_ahead to use git_current_remote instead of origin. Add git_prompt_behind.
This commit is contained in:
parent
a4766e5f15
commit
77f3689b82
1 changed files with 23 additions and 3 deletions
26
lib/git.zsh
26
lib/git.zsh
|
|
@ -5,7 +5,7 @@ function git_prompt_info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks if working tree is dirty
|
# Checks if working tree is dirty
|
||||||
parse_git_dirty() {
|
function parse_git_dirty() {
|
||||||
if [[ -n $(git status -s 2> /dev/null) ]]; then
|
if [[ -n $(git status -s 2> /dev/null) ]]; then
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||||
else
|
else
|
||||||
|
|
@ -15,11 +15,17 @@ parse_git_dirty() {
|
||||||
|
|
||||||
# Checks if there are commits ahead from remote
|
# Checks if there are commits ahead from remote
|
||||||
function git_prompt_ahead() {
|
function git_prompt_ahead() {
|
||||||
if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
if $(echo "$(git log $(git_current_remote)/$(git_current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
|
echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function git_prompt_behind() {
|
||||||
|
if $(echo "$(git log HEAD..$(git_current_remote)/$(git_current_branch) 2> /dev/null)" | grep '^commit' &> /dev/null); then
|
||||||
|
echo "$ZSH_THEME_GIT_PROMPT_BEHIND"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Formats prompt string for current git commit short SHA
|
# Formats prompt string for current git commit short SHA
|
||||||
function git_prompt_short_sha() {
|
function git_prompt_short_sha() {
|
||||||
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
|
SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
|
||||||
|
|
@ -31,7 +37,7 @@ function git_prompt_long_sha() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the status of the working tree
|
# Get the status of the working tree
|
||||||
git_prompt_status() {
|
function git_prompt_status() {
|
||||||
INDEX=$(git status --porcelain 2> /dev/null)
|
INDEX=$(git status --porcelain 2> /dev/null)
|
||||||
STATUS=""
|
STATUS=""
|
||||||
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
|
if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
|
||||||
|
|
@ -60,3 +66,17 @@ git_prompt_status() {
|
||||||
fi
|
fi
|
||||||
echo $STATUS
|
echo $STATUS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function git_current_branch() {
|
||||||
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
||||||
|
echo ${ref#refs/heads/}
|
||||||
|
}
|
||||||
|
|
||||||
|
function git_current_remote() {
|
||||||
|
remote=$(git config --get "branch.$(git_current_branch).remote")
|
||||||
|
if [ -z "$remote" ]; then
|
||||||
|
echo 'origin'
|
||||||
|
else
|
||||||
|
echo "$remote"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue