From fcbca579aef7846e0401a2ca27984178f7f50dc1 Mon Sep 17 00:00:00 2001 From: Ashley Dev Date: Thu, 2 Jun 2011 11:22:39 -0700 Subject: [PATCH] Update plugins/git: - move aliases into plugins/git/git-aliases.plugin.zsh - move git prompt info into plugins/git/git-prompt-old.plugin.zsh - add revamped git prompt info into plugins/git/git-prompt.plugin.zsh - plugins/git/git.plugin.zsh now just sources the above files Added themes/ashleydev.theme.zsh that takes advantage of the new git prompt info --- plugins/git/git-aliases.plugin.zsh | 60 ++++++++++++++++++ .../git/git-prompt-old.plugin.zsh | 42 +++++++++---- .../{git-prompt => git}/git-prompt.plugin.zsh | 5 +- plugins/git/git.plugin.zsh | 63 +------------------ themes/ashleydev.zsh-theme | 2 +- 5 files changed, 96 insertions(+), 76 deletions(-) create mode 100644 plugins/git/git-aliases.plugin.zsh rename lib/git.zsh => plugins/git/git-prompt-old.plugin.zsh (56%) rename plugins/{git-prompt => git}/git-prompt.plugin.zsh (99%) diff --git a/plugins/git/git-aliases.plugin.zsh b/plugins/git/git-aliases.plugin.zsh new file mode 100644 index 000000000..859b637c6 --- /dev/null +++ b/plugins/git/git-aliases.plugin.zsh @@ -0,0 +1,60 @@ +# Aliases +alias g='git' ; compdef g=git +alias ga='git add' ; compdef _git ga=git-add +alias gaa='git add --all' ; compdef _git gaa=git-add +alias gs='git status' ; compdef _git gs=git-status +alias gst='git status' ; compdef _git gst=git-status +# for `gsts ""` +alias gsts='git stash save' ; compdef _git gsts=git-stash +alias gstp='git stash pop' ; compdef _git gstp=git-stash +alias gstl='git stash list' ; compdef _git gstl=git-stash +alias gstll='git stash show -p --stat' ; compdef _git gstll=git-stash +alias gl='git pull' ; compdef _git gl=git-pull +alias gup='git fetch && git rebase' ; compdef _git gup=git-fetch +alias gf='git fetch' ; compdef _git gf=git-fetch +alias gp='git push' ; compdef _git gp=git-push +alias gd='git diff --no-ext-diff -b' ; compdef _git gd=git-diff +alias gdd='git diff --no-ext-diff' ; compdef _git gdd=git-diff +gdv() { git-diff -w "$@" | view - } ; compdef _git gdv=git-diff +alias gc='git commit -v' ; compdef _git gc=git-commit +alias gca='git commit -v -a' ; compdef _git gca=git-commit +alias gco='git checkout' ; compdef _git gco=git-checkout +alias gb='git branch' ; compdef _git gb=git-branch +alias gba='git branch -a' ; compdef _git gba=git-branch +alias gcount='git shortlog -sn' ; compdef gcount=git +alias gcp='git cherry-pick' ; compdef _git gcp=git-cherry-pick +alias gm='git merge' ; compdef _git gm=git-merge +alias glg='git log --stat --max-count=5'; compdef _git glg=git-log + +# Git history (pretty) +local pretty_format_oneline='--pretty=format:"%C(yellow)%h %C(green)%cd %C(cyan)%an %C(bold cyan)%d%C(reset) %s" --date=short' +local pretty_format_medium='--pretty=format:"%C(yellow)commit %H %C(bold cyan)%d%C(reset) +%C(cyan)Author: %an <%ae>%C(reset) +%C(green)Date: %cd%C(reset) +%+s +%+b"' +alias gh="git log --graph $pretty_format_oneline" ; compdef _git gh=git-log +alias ghh="git log --graph $pretty_format_medium" ; compdef _git gh=git-log +alias ghhh="git log --graph --stat $pretty_format_medium" ; compdef _git gh=git-log +alias ghhhh="git log --graph --stat -p --full-diff $pretty_format_medium"; compdef _git gh=git-log + +# Git and svn mix +alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' +compdef _git git-svn-dcommit-push=git + +# +# Will return the current branch name +# Usage example: git pull origin $(current_branch) +# +function current_branch() { + ref=$(git symbolic-ref HEAD 2> /dev/null) || return + echo ${ref#refs/heads/} +} + +# these aliases take advantage of the previous function +alias ggpull='git pull origin $(current_branch)' +compdef _git ggpull=git +alias ggpush='git push origin $(current_branch)' +compdef _git ggpush=git +alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)' +compdef _git ggpnp=git diff --git a/lib/git.zsh b/plugins/git/git-prompt-old.plugin.zsh similarity index 56% rename from lib/git.zsh rename to plugins/git/git-prompt-old.plugin.zsh index 235f9de12..ece86e6d3 100644 --- a/lib/git.zsh +++ b/plugins/git/git-prompt-old.plugin.zsh @@ -1,11 +1,21 @@ -# get the name of the branch we are on +# Renders the name of the current branch. function git_prompt_info() { - ref=$(git symbolic-ref HEAD 2> /dev/null) || return - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + local branch=$(git_current_branch) + if [[ -n "$branch" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" + fi } -# Checks if working tree is dirty -parse_git_dirty() { +# Gets the current branch. +function git_current_branch() { + local ref=$(git symbolic-ref HEAD 2> /dev/null) + if [[ -n "$ref" ]]; then + echo "${ref#refs/heads/}" + fi +} + +# Checks if the working tree is dirty. +function parse_git_dirty() { if [[ -n $(git status -s 2> /dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_DIRTY" else @@ -13,25 +23,31 @@ parse_git_dirty() { fi } -# Checks if there are commits ahead from remote +# Checks if there are commits ahead from remote. 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" fi } -# Formats prompt string for current git commit short SHA +# Formats the prompt string for current git commit 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" + local sha=$(git rev-parse --short HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi } -# Formats prompt string for current git commit long SHA +# Formats the prompt string for current git commit long SHA. function git_prompt_long_sha() { - SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER" + local sha=$(git rev-parse HEAD 2> /dev/null) + if [[ -n "$sha" ]]; then + echo "${ZSH_THEME_GIT_PROMPT_SHA_BEFORE}${sha}${ZSH_THEME_GIT_PROMPT_SHA_AFTER}" + fi } -# Get the status of the working tree -git_prompt_status() { +# Gets the status of the working tree. +function git_prompt_status() { local indicators line untracked added modified renamed deleted while IFS=$'\n' read line; do if [[ "$line" =~ '^\?\? ' ]]; then diff --git a/plugins/git-prompt/git-prompt.plugin.zsh b/plugins/git/git-prompt.plugin.zsh similarity index 99% rename from plugins/git-prompt/git-prompt.plugin.zsh rename to plugins/git/git-prompt.plugin.zsh index 1152f5d4b..5b575be6c 100644 --- a/plugins/git-prompt/git-prompt.plugin.zsh +++ b/plugins/git/git-prompt.plugin.zsh @@ -146,7 +146,7 @@ # r="$_Cr_$r$R" # fi # -# local _prompt="$b$r$s$i$p" +# local _prompt="$b$r$i$s$p" # # add ( ) around _prompt: # if [ $f = 'yes' ]; then # _prompt="($_prompt)" @@ -538,7 +538,6 @@ _git_prompt__dirty_state () if [[ "$line" = \?\?* ]]; then GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes' - GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes' fi if [[ "$line" = \ M* ]]; then GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes' @@ -577,6 +576,8 @@ PERIOD=15 periodic_functions+="_git_prompt_info" _git_prompt_info () { $GIT_PROMPT_INFO_FUNC } +_git_prompt_info + _git_prompt__precmd_update_git_vars() { if [[ $ZSH_VERSION = *\ 4.2* ]]; then diff --git a/plugins/git/git.plugin.zsh b/plugins/git/git.plugin.zsh index 859b637c6..bb515c73a 100644 --- a/plugins/git/git.plugin.zsh +++ b/plugins/git/git.plugin.zsh @@ -1,60 +1,3 @@ -# Aliases -alias g='git' ; compdef g=git -alias ga='git add' ; compdef _git ga=git-add -alias gaa='git add --all' ; compdef _git gaa=git-add -alias gs='git status' ; compdef _git gs=git-status -alias gst='git status' ; compdef _git gst=git-status -# for `gsts ""` -alias gsts='git stash save' ; compdef _git gsts=git-stash -alias gstp='git stash pop' ; compdef _git gstp=git-stash -alias gstl='git stash list' ; compdef _git gstl=git-stash -alias gstll='git stash show -p --stat' ; compdef _git gstll=git-stash -alias gl='git pull' ; compdef _git gl=git-pull -alias gup='git fetch && git rebase' ; compdef _git gup=git-fetch -alias gf='git fetch' ; compdef _git gf=git-fetch -alias gp='git push' ; compdef _git gp=git-push -alias gd='git diff --no-ext-diff -b' ; compdef _git gd=git-diff -alias gdd='git diff --no-ext-diff' ; compdef _git gdd=git-diff -gdv() { git-diff -w "$@" | view - } ; compdef _git gdv=git-diff -alias gc='git commit -v' ; compdef _git gc=git-commit -alias gca='git commit -v -a' ; compdef _git gca=git-commit -alias gco='git checkout' ; compdef _git gco=git-checkout -alias gb='git branch' ; compdef _git gb=git-branch -alias gba='git branch -a' ; compdef _git gba=git-branch -alias gcount='git shortlog -sn' ; compdef gcount=git -alias gcp='git cherry-pick' ; compdef _git gcp=git-cherry-pick -alias gm='git merge' ; compdef _git gm=git-merge -alias glg='git log --stat --max-count=5'; compdef _git glg=git-log - -# Git history (pretty) -local pretty_format_oneline='--pretty=format:"%C(yellow)%h %C(green)%cd %C(cyan)%an %C(bold cyan)%d%C(reset) %s" --date=short' -local pretty_format_medium='--pretty=format:"%C(yellow)commit %H %C(bold cyan)%d%C(reset) -%C(cyan)Author: %an <%ae>%C(reset) -%C(green)Date: %cd%C(reset) -%+s -%+b"' -alias gh="git log --graph $pretty_format_oneline" ; compdef _git gh=git-log -alias ghh="git log --graph $pretty_format_medium" ; compdef _git gh=git-log -alias ghhh="git log --graph --stat $pretty_format_medium" ; compdef _git gh=git-log -alias ghhhh="git log --graph --stat -p --full-diff $pretty_format_medium"; compdef _git gh=git-log - -# Git and svn mix -alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk' -compdef _git git-svn-dcommit-push=git - -# -# Will return the current branch name -# Usage example: git pull origin $(current_branch) -# -function current_branch() { - ref=$(git symbolic-ref HEAD 2> /dev/null) || return - echo ${ref#refs/heads/} -} - -# these aliases take advantage of the previous function -alias ggpull='git pull origin $(current_branch)' -compdef _git ggpull=git -alias ggpush='git push origin $(current_branch)' -compdef _git ggpush=git -alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)' -compdef _git ggpnp=git +source $ZSH/plugins/git/git-aliases.plugin.zsh +source $ZSH/plugins/git/git-prompt-old.plugin.zsh +source $ZSH/plugins/git/git-prompt.plugin.zsh diff --git a/themes/ashleydev.zsh-theme b/themes/ashleydev.zsh-theme index be4710cd2..bf0932768 100644 --- a/themes/ashleydev.zsh-theme +++ b/themes/ashleydev.zsh-theme @@ -109,7 +109,7 @@ update__GIT_PROMPT_INFO () r="$_Cr_$r$R" fi - local _prompt="$b$r$s$i$p" + local _prompt="$b$r$i$s$p" # add ( ) around _prompt: if [ "$f" = 'yes' ]; then _prompt="($_prompt)"