From c2011e55cd215d08608564e7b28801ccca2d5f09 Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Sun, 27 Jan 2013 11:20:09 +0100 Subject: [PATCH] Added my own theme, based on bira Added a new theme based on bira and these async prompt instructions, which adds the git status asynchronously, making it significantly easier to work on huge repos (e.g. Chromium, WebKit). --- themes/asyncbira.zsh-theme | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 themes/asyncbira.zsh-theme diff --git a/themes/asyncbira.zsh-theme b/themes/asyncbira.zsh-theme new file mode 100644 index 000000000..e8dc86e29 --- /dev/null +++ b/themes/asyncbira.zsh-theme @@ -0,0 +1,59 @@ +# ZSH Theme - Preview: http://gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png +local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" + +local user_host='%{$terminfo[bold]$fg[green]%}%n@%m%{$reset_color%}' +local current_dir='%{$terminfo[bold]$fg[blue]%} %~%{$reset_color%}' +local rvm_ruby='' +if which rvm-prompt &> /dev/null; then + rvm_ruby='%{$fg[red]%}‹$(rvm-prompt i v g)›%{$reset_color%}' +else + if which rbenv &> /dev/null; then + rvm_ruby='%{$fg[red]%}‹$(rbenv version | sed -e "s/ (set.*$//")›%{$reset_color%}' + fi +fi + +setopt prompt_subst + +PROMPT="╭ ${user_host} %t ${current_dir} ${rvm_ruby} +╰ %B$%b " +RPROMPT="" +RPS1="${return_code}" + +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹" +ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%}" +ZSH_THEME_GIT_PROMPT_CLEAN="✔" +ZSH_THEME_GIT_PROMPT_DIRTY="✗" + +ASYNC_PROC=0 +function precmd() { + function async() { + # save to temp file + printf "%s" "$(git_prompt_info)" > "${HOME}/.zsh_tmp_prompt" + + # signal parent + kill -s USR1 $$ + } + + # do not clear RPROMPT, let it persist + + # kill child if necessary + if [[ "${ASYNC_PROC}" != 0 ]]; then + kill -s HUP $ASYNC_PROC >/dev/null 2>&1 || : + fi + + # start background computation + async &! + ASYNC_PROC=$! +} + +function TRAPUSR1() { + # read from temp file + PROMPT="╭ ${user_host} %t ${current_dir} ${rvm_ruby} $(cat ${HOME}/.zsh_tmp_prompt) +╰ %B$%b " + + # reset proc number + ASYNC_PROC=0 + + # redisplay + zle && zle reset-prompt +}