From c1dfabba696b8246209fdc15d3c3d3f0261fd968 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 1 Apr 2012 20:27:37 -0700 Subject: [PATCH 1/6] lib/git.zsh: Allow users to opt-out of git version checks If we pre-define POST_GIT_1_7_2 then we can skip out on an extra call to `git version`. --- lib/git.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index 96598cf5f..b8b5bab61 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -134,8 +134,8 @@ function git_compare_version() { } #this is unlikely to change so make it all statically assigned -POST_1_7_2_GIT=$(git_compare_version "1.7.2") +if [[ -z "$POST_1_7_2_GIT" ]]; then + POST_1_7_2_GIT=$(git_compare_version "1.7.2") +fi #clean up the namespace slightly by removing the checker function unset -f git_compare_version - - From a481661251fc48dbd8f28e23fb2d4e2fbd3d1e80 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 1 Apr 2012 20:28:58 -0700 Subject: [PATCH 2/6] lib/git.zsh: Allow themes to opt-out of an expensive git status call If neither DIRTY nor CLEAN is defined then this function is a noop, so check up-front before making the call. This speeds up prompts that empty out these values. --- lib/git.zsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/git.zsh b/lib/git.zsh index b8b5bab61..148695643 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -8,6 +8,11 @@ function git_prompt_info() { # Checks if working tree is dirty parse_git_dirty() { + if [[ -z "$ZSH_THEME_GIT_PROMPT_DIRTY" && + -z "$ZSH_THEME_GIT_PROMPT_CLEAN" ]]; then + return + fi + local SUBMODULE_SYNTAX='' local GIT_STATUS='' local CLEAN_MESSAGE='nothing to commit (working directory clean)' From fd44dfd03f46eea40975b96375c3f392f191dd27 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 1 Apr 2012 20:30:24 -0700 Subject: [PATCH 3/6] lib/git.zsh: Speed-up git_prompt_ahead() Use the `git rev-list` plumbing instead of `git log`, which allows us to do without grep. Limit the history to one commit as well. --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 148695643..444b30f3d 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -57,7 +57,7 @@ git_remote_status() { # 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 [[ -n $(git rev-list -1 origin/$(current_branch)..HEAD 2>/dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_AHEAD" fi } From 2bb066eed54711434444a11c5580bbf4238908fa Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 7 Apr 2012 19:16:51 -0700 Subject: [PATCH 4/6] lib/git.zsh: Avoid calling current_branch() The original code hard-coded 'origin' as the remote and called current_branch() to get the corresponding remote branch name, which may not necessarily be the correct upstream branch. Use the the built-in @{upstream} syntax instead of calling current_branch(). This improves performance and fixes a bug when the local and remote branches do not have the same name. --- lib/git.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git.zsh b/lib/git.zsh index 444b30f3d..17b05d59d 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -57,7 +57,7 @@ git_remote_status() { # Checks if there are commits ahead from remote function git_prompt_ahead() { - if [[ -n $(git rev-list -1 origin/$(current_branch)..HEAD 2>/dev/null) ]]; then + if [[ -n $(git rev-list -1 --first-parent @{upstream}..HEAD 2>/dev/null) ]]; then echo "$ZSH_THEME_GIT_PROMPT_AHEAD" fi } From b36d02c2a348c82478ff5b58102b0e91c02e2baf Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 7 Apr 2012 19:22:19 -0700 Subject: [PATCH 5/6] ilb/git.zsh: Optimize git_prompt_status() Avoid looking for dirty submodules when git >= 1.7.2 using the --ignore-submodules=dirty option. Avoid looking at untracked files and other types of files when the theme does not display them. This dramatically speeds up performance. --- lib/git.zsh | 108 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 76 insertions(+), 32 deletions(-) diff --git a/lib/git.zsh b/lib/git.zsh index 17b05d59d..2ac6c97a8 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -15,7 +15,7 @@ parse_git_dirty() { local SUBMODULE_SYNTAX='' local GIT_STATUS='' - local CLEAN_MESSAGE='nothing to commit (working directory clean)' + if [[ "$(git config --get oh-my-zsh.hide-status)" != "1" ]]; then if [[ $POST_1_7_2_GIT -gt 0 ]]; then SUBMODULE_SYNTAX="--ignore-submodules=dirty" @@ -74,48 +74,92 @@ function git_prompt_long_sha() { # Get the status of the working tree git_prompt_status() { - INDEX=$(git status --porcelain -b 2> /dev/null) + local NO_DIRTY_SUBMODULES='' + local NO_UNTRACKED='' + + if [[ $POST_1_7_2_GIT -gt 0 ]]; then + NO_DIRTY_SUBMODULES="--ignore-submodules=dirty" + fi + + if [[ -z "$ZSH_THEME_GIT_PROMPT_UNTRACKED" ]]; then + NO_UNTRACKED="--untracked-files=no" + fi + + # This could use --porcelain but git does not print + # the branch ahead/behind information when --porcelain is used. + INDEX=$(git status -s -b ${NO_DIRTY_SUBMODULES} ${NO_UNTRACKED} 2>/dev/null) STATUS="" - if $(echo "$INDEX" | grep -E '^\?\? ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED" ]]; then + if echo "$INDEX" | grep -E '^\?\? ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS" + fi fi - if $(echo "$INDEX" | grep '^A ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" - elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_ADDED" ]]; then + if echo "$INDEX" | grep '^A ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + elif echo "$INDEX" | grep '^M ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" + fi fi - if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" - elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_MODIFIED" ]]; then + if echo "$INDEX" | grep '^ M ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + elif echo "$INDEX" | grep '^AM ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + elif echo "$INDEX" | grep '^ T ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS" + fi fi - if $(echo "$INDEX" | grep '^R ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_RENAMED" ]]; then + if echo "$INDEX" | grep '^R ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS" + fi fi - if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" - elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" - elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_DELETED" ]]; then + if echo "$INDEX" | grep '^ D ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + elif echo "$INDEX" | grep '^D ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + elif echo "$INDEX" | grep '^AD ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS" + fi fi - if $(git rev-parse --verify refs/stash >/dev/null 2>&1); then - STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_STASHED" ]]; then + if git rev-parse --verify refs/stash &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS" + fi fi - if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_UNMERGED" ]]; then + if echo "$INDEX" | grep '^UU ' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS" + fi fi - if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_AHEAD" ]]; then + if echo "$INDEX" | grep '^## .*ahead' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS" + fi fi - if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_BEHIND" ]]; then + if echo "$INDEX" | grep '^## .*behind' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS" + fi fi - if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then - STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" + + if [[ -n "$ZSH_THEME_GIT_PROMPT_DIVERGED" ]]; then + if echo "$INDEX" | grep '^## .*diverged' &> /dev/null; then + STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS" + fi fi + echo $STATUS } From b0b47193d180f4821afa6e0b216eb58908e3e0b5 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 27 Apr 2013 01:57:35 -0700 Subject: [PATCH 6/6] Add davvid theme --- themes/davvid.zsh-theme | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 themes/davvid.zsh-theme diff --git a/themes/davvid.zsh-theme b/themes/davvid.zsh-theme new file mode 100644 index 000000000..91154fda6 --- /dev/null +++ b/themes/davvid.zsh-theme @@ -0,0 +1,18 @@ +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[gray]%}:%{$reset_color%}%{$reset_color%}%{$fg[blue]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " + +ZSH_THEME_GIT_PROMPT_DIRTY="" +ZSH_THEME_GIT_PROMPT_CLEAN="" + +ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[yellow]%}>" +ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg[yellow]%}<" +ZSH_THEME_GIT_PROMPT_DIVERGED="%{$fg[yellow]%}<>" + +ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[green]%}+" +ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[red]%}*" +ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}-" +ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[red]%}=" +ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[red]%}!" + +PROMPT='%{$fg[gray]%}#%{$reset_color%}%{$fg[blue]%}%n%{$reset_color%}%{$fg[gray]%}@%{$reset_color%}%{$fg[blue]%}%m%{$reset_color%}%{$fg[gray]%}:%{$reset_color%}%{$fg[white]%}%0~%{$reset_color%}$(git_prompt_info)$(git_prompt_status) %{$fg[cyan]%} +$%{$reset_color%} '