diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 51a20595..73c9943a 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -546,8 +546,28 @@ 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. +.. 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. + +If you want to disable prompt in shell, but still have tmux support or if you +want to disable tmux support you can use variables +``$POWERLINE_NO_{SHELL}_PROMPT``/``$POWERLINE_NO_SHELL_PROMPT`` and +``$POWERLINE_NO_{SHELL}_TMUX_SUPPORT``/``$POWERLINE_NO_SHELL_TMUX_SUPPORT`` +(substitute ``{SHELL}`` with the name of the shell (all-caps) you want to +disable support for (e.g. ``BASH``) or use all-inclusive ``SHELL`` that will +disable support for all shells). These variables have no effect after +configuration script was sourced (in fish case: after ``powerline-setup`` +function was run). To disable specific feature support set one of these +variables to some non-empty value. + +.. note:: + + Most supported shells’ configuration scripts check for additional + configuration variables being empty. But tcsh configuration script checks + for variables being *defined*, not empty. diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index 6f1de23b..9271e9bd 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -1,14 +1,3 @@ -if test -z "${POWERLINE_COMMAND}" ; then - if which powerline-client &>/dev/null ; then - export POWERLINE_COMMAND=powerline-client - elif which powerline &>/dev/null ; then - export POWERLINE_COMMAND=powerline - else - # `$0` is set to `-bash` when using SSH so that won't work - export POWERLINE_COMMAND="$(dirname "$BASH_SOURCE")/../../../scripts/powerline" - fi -fi - _powerline_init_tmux_support() { if test -n "$TMUX" && tmux refresh -S &>/dev/null ; then # TMUX variable may be unset to create new tmux session inside this one @@ -46,7 +35,24 @@ _powerline_prompt() { return $last_exit_code } -test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_prompt*}" || - export PROMPT_COMMAND=$'_powerline_prompt\n'"${PROMPT_COMMAND}" +_powerline_setup_prompt() { + if test -z "${POWERLINE_COMMAND}" ; then + if which powerline-client &>/dev/null ; then + export POWERLINE_COMMAND=powerline-client + elif which powerline &>/dev/null ; then + export POWERLINE_COMMAND=powerline + else + # `$0` is set to `-bash` when using SSH so that won't work + export POWERLINE_COMMAND="$(dirname "$BASH_SOURCE")/../../../scripts/powerline" + fi + fi + test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_prompt*}" || + export PROMPT_COMMAND=$'_powerline_prompt\n'"${PROMPT_COMMAND}" +} -_powerline_init_tmux_support +if test -z "$POWERLINE_NO_BASH_PROMPT$POWERLINE_NO_SHELL_PROMPT" ; then + _powerline_setup_prompt +fi +if test -z "$POWERLINE_NO_BASH_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" ; then + _powerline_init_tmux_support +fi diff --git a/powerline/bindings/fish/powerline-setup.fish b/powerline/bindings/fish/powerline-setup.fish index d925a6fc..50eb5302 100644 --- a/powerline/bindings/fish/powerline-setup.fish +++ b/powerline/bindings/fish/powerline-setup.fish @@ -1,39 +1,43 @@ function powerline-setup - if test -z "$POWERLINE_COMMAND" - if which powerline-client >/dev/null - set -g -x POWERLINE_COMMAND powerline-client - else if which powerline >/dev/null - set -g -x POWERLINE_COMMAND powerline - else - set -g -x POWERLINE_COMMAND (dirname (status -f))/../../../scripts/powerline + if test -z "$POWERLINE_NO_FISH_PROMPT$POWERLINE_NO_SHELL_PROMPT" + if test -z "$POWERLINE_COMMAND" + if which powerline-client >/dev/null + set -g -x POWERLINE_COMMAND powerline-client + else if which powerline >/dev/null + set -g -x POWERLINE_COMMAND powerline + else + set -g -x POWERLINE_COMMAND (dirname (status -f))/../../../scripts/powerline + end end + function --on-variable POWERLINE_COMMAND _powerline_update + set -l addargs "--last_exit_code=\$status --last_pipe_status=\$status --jobnum=(jobs -p | wc -l)" + eval " + function fish_prompt + $POWERLINE_COMMAND shell left $addargs + end + function fish_right_prompt + $POWERLINE_COMMAND shell right $addargs + end + " + end + _powerline_update end - function --on-variable POWERLINE_COMMAND _powerline_update - set -l addargs "--last_exit_code=\$status --last_pipe_status=\$status --jobnum=(jobs -p | wc -l)" - eval " - function fish_prompt - $POWERLINE_COMMAND shell left $addargs - end - function fish_right_prompt - $POWERLINE_COMMAND shell right $addargs - end - " - end - _powerline_update - if test -n "$TMUX" - if tmux refresh -S ^/dev/null - function _powerline_tmux_setenv - tmux setenv -g TMUX_$argv[1]_(tmux display -p "#D" | tr -d "%") "$argv[2]" - tmux refresh -S + if test -z "$POWERLINE_NO_FISH_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" + if test -n "$TMUX" + if tmux refresh -S ^/dev/null + function _powerline_tmux_setenv + tmux setenv -g TMUX_$argv[1]_(tmux display -p "#D" | tr -d "%") "$argv[2]" + tmux refresh -S + end + function --on-variable PWD _powerline_tmux_set_pwd + _powerline_tmux_setenv PWD "$PWD" + end + function --on-signal WINCH _powerline_tmux_set_columns + _powerline_tmux_setenv COLUMNS "$COLUMNS" + end + _powerline_tmux_set_columns + _powerline_tmux_set_pwd end - function --on-variable PWD _powerline_tmux_set_pwd - _powerline_tmux_setenv PWD "$PWD" - end - function --on-signal WINCH _powerline_tmux_set_columns - _powerline_tmux_setenv COLUMNS "$COLUMNS" - end - _powerline_tmux_set_columns - _powerline_tmux_set_pwd end end end diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh index 68e031e8..eb6acac1 100644 --- a/powerline/bindings/tcsh/powerline.tcsh +++ b/powerline/bindings/tcsh/powerline.tcsh @@ -14,8 +14,12 @@ if ! $?POWERLINE_COMMAND then setenv POWERLINE_COMMAND $POWERLINE_SOURCED:h:h:h:h:q/scripts/powerline endif endif -alias _powerline_tmux_set_pwd 'if ( $?TMUX && { tmux refresh -S >&/dev/null } ) tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if ( $?TMUX ) tmux refresh -S >&/dev/null' -alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r tcsh_prompt --last_exit_code=$?`"' -alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r tcsh_prompt --last_exit_code=$?` "' -alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd" -alias precmd "`alias precmd` ; _powerline_set_prompt ; _powerline_set_rprompt" +if ! ( $?POWERLINE_NO_TCSH_TMUX_SUPPORT || $?POWERLINE_NO_SHELL_TMUX_SUPPORT ) then + alias _powerline_tmux_set_pwd 'if ( $?TMUX && { tmux refresh -S >&/dev/null } ) tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if ( $?TMUX ) tmux refresh -S >&/dev/null' + alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd" +endif +if ! ( $?POWERLINE_NO_TCSH_PROMPT || $?POWERLINE_NO_SHELL_PROMPT ) then + alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r tcsh_prompt --last_exit_code=$?`"' + alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r tcsh_prompt --last_exit_code=$?` "' + alias precmd "`alias precmd` ; _powerline_set_prompt ; _powerline_set_rprompt" +endif diff --git a/powerline/bindings/zsh/powerline.zsh b/powerline/bindings/zsh/powerline.zsh index 976190c1..47673f0f 100644 --- a/powerline/bindings/zsh/powerline.zsh +++ b/powerline/bindings/zsh/powerline.zsh @@ -150,6 +150,10 @@ _powerline_add_widget() { setopt promptpercent setopt promptsubst -_powerline_setup_prompt -_powerline_init_tmux_support -_powerline_init_modes_support +if test -z "$POWERLINE_NO_ZSH_PROMPT$POWERLINE_NO_SHELL_PROMPT" ; then + _powerline_setup_prompt + _powerline_init_modes_support +fi +if test -z "$POWERLINE_NO_ZSH_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" ; then + _powerline_init_tmux_support +fi