1
0
Fork 0

sorin prompt improvements - rbenv/pyenv support

cleaned up unnecessary prompt async functions

autoload async

rewrote sorin prompt to use zsh-async

removing dead variables

actually working now

moving code for a saner diff

fixed last async issues
pull/924/head
Matthew Crenshaw 10 years ago
parent c38c2dd909
commit 17a57fcda0

@ -1,11 +1,17 @@
# #
# A simple theme that displays relevant, contextual information. # A simple theme that displays relevant, contextual information.
# #
# - Git branch
# - Python environment
# - Ruby environment (gemset)
#
# Authors: # Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com> # Sorin Ionescu <sorin.ionescu@gmail.com>
# Matthew Crenshaw <sgt@squig.gs>
# #
# Screenshots: # Screenshots:
# http://i.imgur.com/nrGV6pg.png # http://i.imgur.com/nrGV6pg.png
# http://i.imgur.com/w2ein8H.png
# #
# #
@ -32,36 +38,38 @@
# Load dependencies. # Load dependencies.
pmodload 'helper' pmodload 'helper'
prompt_sorin_git_info() { function _prompt_sorin_async_job {
if (( _prompt_sorin_precmd_async_pid > 0 )); then prompt_sorin_style
# Append Git status. local output=''
if [[ -s "$_prompt_sorin_precmd_async_data" ]]; then builtin cd -q $1
alias typeset='typeset -g' if (( $+functions[python-info] )); then
source "$_prompt_sorin_precmd_async_data" python-info
RPROMPT+='${git_info:+${(e)git_info[status]}}' output+=" ${python_info:+${(e)python_info[virtualenv]}}"
unalias typeset fi
fi if (( $+functions[ruby-info] )); then
ruby-info
# Reset PID. output+=" ${ruby_info:+${(e)ruby_info[version]}}"
_prompt_sorin_precmd_async_pid=0
# Redisplay prompt.
zle && zle reset-prompt
fi fi
}
function prompt_sorin_precmd_async {
# Get Git repository information.
if (( $+functions[git-info] )); then if (( $+functions[git-info] )); then
git-info git-info
typeset -p git_info >! "$_prompt_sorin_precmd_async_data" output+=" ${git_info:+${(e)git_info[status]}}"
fi fi
print $output
}
function _prompt_sorin_callback {
local job=$1 code=$2 output=$3 exec_time=$4
# Signal completion to parent process. if [[ -n $output ]]; then
kill -WINCH $$ # Append to rprompt
RPROMPT+=$output
# Redisplay prompt.
zle && zle reset-prompt
fi
} }
function prompt_sorin_precmd { function _prompt_sorin_precmd {
setopt LOCAL_OPTIONS setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS unsetopt XTRACE KSH_ARRAYS
@ -71,30 +79,46 @@ function prompt_sorin_precmd {
# Define prompts. # Define prompts.
RPROMPT='${editor_info[overwrite]}%(?:: %F{1}⏎%f)${VIM:+" %B%F{6}V%f%b"}' RPROMPT='${editor_info[overwrite]}%(?:: %F{1}⏎%f)${VIM:+" %B%F{6}V%f%b"}'
# Kill the old process of slow commands if it is still running. # Kill any currently running async jobs
if (( _prompt_sorin_precmd_async_pid > 0 )); then async_flush_jobs 'prompt_sorin'
kill -KILL "$_prompt_sorin_precmd_async_pid" &>/dev/null
fi
# Compute slow commands in the background. # We need the worker's env to be up to date, so here we are restarting the worker
trap prompt_sorin_git_info WINCH async_stop_worker 'prompt_sorin'
prompt_sorin_precmd_async &! async_start_worker 'prompt_sorin' -n -u
_prompt_sorin_precmd_async_pid=$! async_register_callback 'prompt_sorin' _prompt_sorin_callback
# Kick off async jobs
async_job 'prompt_sorin' _prompt_sorin_async_job "$(pwd)"
} }
function prompt_sorin_setup { function prompt_sorin_setup {
setopt LOCAL_OPTIONS setopt LOCAL_OPTIONS
unsetopt XTRACE KSH_ARRAYS unsetopt XTRACE KSH_ARRAYS
prompt_opts=(cr percent subst) prompt_opts=(cr percent subst)
_prompt_sorin_precmd_async_pid=0
_prompt_sorin_precmd_async_data="${TMPPREFIX}-prompt_sorin_data"
# Load required functions. # Load required functions.
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
autoload -Uz async && async
# Start async worker
# async_start_worker 'prompt_sorin' -n -u
# Register callback
# async_register_callback 'prompt_sorin' _prompt_sorin_callback
# Add hook for calling git-info before each command. # Add hook for calling git-info before each command.
add-zsh-hook precmd prompt_sorin_precmd add-zsh-hook precmd _prompt_sorin_precmd
# Apply styles
prompt_sorin_style
# Define prompts.
PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} '
RPROMPT=''
SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? '
}
function prompt_sorin_style {
# Set editor-info parameters. # Set editor-info parameters.
zstyle ':prezto:module:editor:info:completing' format '%B%F{7}...%f%b' zstyle ':prezto:module:editor:info:completing' format '%B%F{7}...%f%b'
zstyle ':prezto:module:editor:info:keymap:primary' format ' %B%F{1}%F{3}%F{2}%f%b' zstyle ':prezto:module:editor:info:keymap:primary' format ' %B%F{1}%F{3}%F{2}%f%b'
@ -119,10 +143,11 @@ function prompt_sorin_setup {
zstyle ':prezto:module:git:info:keys' format \ zstyle ':prezto:module:git:info:keys' format \
'status' '$(coalesce "%b" "%p" "%c")%s%A%B%S%a%d%m%r%U%u' 'status' '$(coalesce "%b" "%p" "%c")%s%A%B%S%a%d%m%r%U%u'
# Define prompts. # Set ruby-info parameters.
PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} ' zstyle ':prezto:module:ruby:info:version' format ' %F{4}rbenv%f:%F{2}%v%f'
RPROMPT=''
SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? ' # Set python-info parameters.
zstyle ':prezto:module:python:info:virtualenv' format ' %F{4}pyenv%f:%F{2}%v%f'
} }
function prompt_sorin_preview { function prompt_sorin_preview {

Loading…
Cancel
Save