mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-01-02 02:19:06 +01:00
git functions cleanup
* moved current_branch implementation in lib/git.zsh and renamed to git_current_branch * renamed parse_git_dirty to git_parse_dirty, still backwards compatible
This commit is contained in:
parent
027fcccc92
commit
f8a602e6f9
2 changed files with 13 additions and 11 deletions
18
lib/git.zsh
18
lib/git.zsh
|
|
@ -1,13 +1,18 @@
|
||||||
# get the name of the branch we are on
|
# get the name of the branch we are on
|
||||||
function git_prompt_info() {
|
function git_current_branch() {
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
||||||
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
|
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
echo ${ref#refs/heads/}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Branch and dirty flag
|
||||||
|
function git_prompt_info() {
|
||||||
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
||||||
|
echo "$ZSH_THEME_GIT_PROMPT_PREFIX$(git_current_branch)$(git_parse_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
||||||
|
}
|
||||||
|
|
||||||
# Checks if working tree is dirty
|
# Checks if working tree is dirty
|
||||||
parse_git_dirty() {
|
function git_parse_dirty() {
|
||||||
local SUBMODULE_SYNTAX=''
|
local SUBMODULE_SYNTAX=''
|
||||||
if [[ $POST_1_7_2_GIT -gt 0 ]]; then
|
if [[ $POST_1_7_2_GIT -gt 0 ]]; then
|
||||||
SUBMODULE_SYNTAX="--ignore-submodules=dirty"
|
SUBMODULE_SYNTAX="--ignore-submodules=dirty"
|
||||||
|
|
@ -18,11 +23,12 @@ parse_git_dirty() {
|
||||||
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
# For backwards compatibility
|
||||||
|
function parse_git_dirty() { git_parse_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 origin/$(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
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +44,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
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,7 @@ alias gsd='git svn dcommit'
|
||||||
# Will return the current branch name
|
# Will return the current branch name
|
||||||
# Usage example: git pull origin $(current_branch)
|
# Usage example: git pull origin $(current_branch)
|
||||||
#
|
#
|
||||||
function current_branch() {
|
function current_branch() { git_current_branch }
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
|
||||||
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
|
|
||||||
echo ${ref#refs/heads/}
|
|
||||||
}
|
|
||||||
|
|
||||||
function current_repository() {
|
function current_repository() {
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue