Add zsh prompt script for sourcing in zshrc

This script sets a couple of environment variables in tmux if it's
running, and provides the last exit code and last pipe status to
powerline-prompt. It also traps SIGWINCH and sets the window width as an
env variable in tmux. The default prompt has been split in two and the
git branch is moved to RPS1.

The script must be sourced with an absolute path for now:

    . /path/to/powerline/bindings/zsh/prompt.zsh

Statusline cropping has not been implemented in powerline-tmux yet.

Closes #82.
Closes #83.
Refs #90.
This commit is contained in:
Kim Silkebækken 2013-01-22 13:25:01 +01:00
parent cfe47adc96
commit 487aef3af7

View File

@ -0,0 +1,33 @@
_powerline_precmd() {
export PS1="$(powerline-prompt --renderer_module=zsh_prompt --last_exit_code=$? --last_pipe_status=$pipestatus left)"
export RPS1="$(powerline-prompt --renderer_module=zsh_prompt --last_exit_code=$? --last_pipe_status=$pipestatus right)"
_powerline_tmux_set_pwd
}
_powerline_tmux_setenv() {
if [[ -n "$TMUX" ]]; then
tmux setenv TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
fi
}
_powerline_tmux_set_pwd() {
_powerline_tmux_setenv PWD "$PWD"
}
_powerline_tmux_set_columns() {
_powerline_tmux_setenv COLUMNS "$COLUMNS"
}
_powerline_install_precmd() {
for f in "${precmd_functions[@]}"; do
if [[ "$f" = "_powerline_precmd" ]]; then
return
fi
done
precmd_functions+=(_powerline_precmd)
}
trap "_powerline_tmux_set_columns" SIGWINCH
kill -SIGWINCH $$
_powerline_install_precmd