From 884a8b0d7866d25fe22bf90cef79461ea63f014d Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 24 May 2013 06:25:48 +0400 Subject: [PATCH 1/3] Use powerline-client if possible --- powerline/bindings/bash/powerline.sh | 10 +++++++++- powerline/bindings/tmux/powerline.conf | 6 ++++-- powerline/bindings/zsh/powerline.zsh | 12 ++++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index ba33e2aa..cc0a22cc 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -1,3 +1,11 @@ +if test -z "${POWERLINE_COMMAND}" ; then + if which powerline-client &>/dev/null ; then + export POWERLINE_COMMAND=powerline-client + else + export POWERLINE_COMMAND=powerline + fi +fi + _powerline_tmux_setenv() { if [[ -n "$TMUX" ]]; then tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2" @@ -22,7 +30,7 @@ _powerline_prompt() { local last_exit_code=$? [[ -z "$POWERLINE_OLD_PROMPT_COMMAND" ]] || eval $POWERLINE_OLD_PROMPT_COMMAND - PS1="$(powerline shell left -r bash_prompt --last_exit_code=$last_exit_code)" + PS1="$($POWERLINE_COMMAND shell left -r bash_prompt --last_exit_code=$last_exit_code)" _powerline_tmux_set_pwd return $last_exit_code } diff --git a/powerline/bindings/tmux/powerline.conf b/powerline/bindings/tmux/powerline.conf index 5951848c..81eda186 100644 --- a/powerline/bindings/tmux/powerline.conf +++ b/powerline/bindings/tmux/powerline.conf @@ -1,11 +1,13 @@ +if-shell 'test -z "$POWERLINE_COMMAND"' 'if-shell "which powerline-client" "set-environment -g POWERLINE_COMMAND powerline-client" "set-environment -g POWERLINE_COMMAND powerline"' set -g status on set -g status-utf8 on set -g status-interval 2 set -g status-fg colour231 set -g status-bg colour234 set -g status-left-length 20 -set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#(powerline tmux left)' -set -g status-right '#(powerline tmux right -R pane_id=`tmux display -p "#D"`)' +set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#($POWERLINE_COMMAND tmux left)' +set -g status-right '#($POWERLINE_COMMAND tmux right -R pane_id=`tmux display -p "#D"`)' set -g status-right-length 150 set -g window-status-format "#[fg=colour244,bg=colour234]#I #[fg=colour240] #[fg=colour249]#W " set -g window-status-current-format "#[fg=colour234,bg=colour31]#[fg=colour117,bg=colour31] #I  #[fg=colour231,bold]#W #[fg=colour31,bg=colour234,nobold]" +# vim: ft=tmux diff --git a/powerline/bindings/zsh/powerline.zsh b/powerline/bindings/zsh/powerline.zsh index 89b86cff..e5b8d6d8 100644 --- a/powerline/bindings/zsh/powerline.zsh +++ b/powerline/bindings/zsh/powerline.zsh @@ -1,3 +1,11 @@ +if test -z "${POWERLINE_COMMAND}" ; then + if which powerline-client &>/dev/null ; then + export POWERLINE_COMMAND=powerline-client + else + export POWERLINE_COMMAND=powerline + fi +fi + _powerline_tmux_setenv() { emulate -L zsh if [[ -n "$TMUX" ]]; then @@ -27,8 +35,8 @@ _powerline_install_precmd() { zpython 'powerline_setup()' zpython 'del powerline_setup' else - PS1='$(powerline shell left -r zsh_prompt --last_exit_code=$? --last_pipe_status="$pipestatus")' - RPS1='$(powerline shell right -r zsh_prompt --last_exit_code=$? --last_pipe_status="$pipestatus")' + PS1='$($POWERLINE_COMMAND shell left -r zsh_prompt --last_exit_code=$? --last_pipe_status="$pipestatus")' + RPS1='$($POWERLINE_COMMAND shell right -r zsh_prompt --last_exit_code=$? --last_pipe_status="$pipestatus")' fi } From 374da15667c327e0a9e8e713afc97db6a6d6b9a5 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 24 May 2013 07:18:03 +0400 Subject: [PATCH 2/3] Use eval in tmux/powerline.conf fish does not support variables used as commands --- powerline/bindings/tmux/powerline.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerline/bindings/tmux/powerline.conf b/powerline/bindings/tmux/powerline.conf index 81eda186..ba75336e 100644 --- a/powerline/bindings/tmux/powerline.conf +++ b/powerline/bindings/tmux/powerline.conf @@ -5,8 +5,8 @@ set -g status-interval 2 set -g status-fg colour231 set -g status-bg colour234 set -g status-left-length 20 -set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#($POWERLINE_COMMAND tmux left)' -set -g status-right '#($POWERLINE_COMMAND tmux right -R pane_id=`tmux display -p "#D"`)' +set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#(eval $POWERLINE_COMMAND tmux left)' +set -g status-right '#(eval $POWERLINE_COMMAND tmux right -R pane_id=`tmux display -p "#D"`)' set -g status-right-length 150 set -g window-status-format "#[fg=colour244,bg=colour234]#I #[fg=colour240] #[fg=colour249]#W " set -g window-status-current-format "#[fg=colour234,bg=colour31]#[fg=colour117,bg=colour31] #I  #[fg=colour231,bold]#W #[fg=colour31,bg=colour234,nobold]" From baa44475e547e6bf908585f3863715095f076852 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 24 May 2013 07:21:40 +0400 Subject: [PATCH 3/3] Add note about POWERLINE_COMMAND to documentation --- docs/source/configuration.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 40adca33..073afdde 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -526,3 +526,18 @@ use ``c.Powerline.KEY``. Supported ``KEY`` strings or keyword argument names: Sets directory where configuration should be read from. If present, no default locations are searched for configuration. No expansions are performed thus you cannot use paths starting with ``~/``. + +Prompt command +-------------- + +In addition to the above configuration options you can use +``$POWERLINE_COMMAND`` environment variable to tell shell or tmux to use +specific powerline implementation. This is mostly useful for putting powerline +into different directory or replacing ``powerline`` script with +``powerline-client`` for performance reasons. + +Note: ``$POWERLINE_COMMAND`` appears in shell scripts without quotes thus you +can specify additional parameters in bash. In zsh you will have to make +``$POWERLINE_COMMAND`` an array parameter to achieve the same result. In tmux it +is passed to ``eval`` and depends on the shell used. POSIX-compatible shells, +zsh, bash and fish will split this variable in this case.