diff --git a/docs/source/usage/shell-prompts.rst b/docs/source/usage/shell-prompts.rst index e2dbc1d6..75fe7a3e 100644 --- a/docs/source/usage/shell-prompts.rst +++ b/docs/source/usage/shell-prompts.rst @@ -2,6 +2,16 @@ Shell prompts ************* +.. note:: + Powerline daemon is not run automatically by any of my bindings. It is + advised that you add + + .. code-block:: bash + + powerline-daemon -q + + before any other powerline-related code in your shell configuration file. + Bash prompt =========== @@ -12,6 +22,28 @@ the absolute path to your Powerline installation directory: . {repository_root}/powerline/bindings/bash/powerline.sh +.. note:: + Since without powerline daemon bash bindings are very slow PS2 + (continuation) and PS3 (select) prompts are not set up. Thus it is advised + to use + + .. code-block:: bash + + powerline-daemon -q + POWERLINE_BASH_CONTINUATION=1 + POWERLINE_BASH_SELECT=1 + . {repository_root}/powerline/bindings/bash/powerline.sh + + in your bash configuration file. Without ``POWERLINE_BASH_*`` variables PS2 + and PS3 prompts are computed exactly once at bash startup. + +.. warning:: + At maximum bash continuation PS2 and select PS3 prompts are computed each + time main PS1 prompt is computed. Do not expect it to work properly if you + e.g. put current time there. + + At minimum they are computed once on startup. + Zsh prompt ========== @@ -59,6 +91,20 @@ following in ``~/.profile``: will source (using ``.`` command) both former ``$ENV`` file and :file:`powerline.sh` files and set ``$ENV`` to the path of this new file. +.. warning:: + Mksh users have to set ``$POWERLINE_SHELL_CONTINUATION`` and + ``$POWERLINE_SHELL_SELECT`` to 1 to get PS2 and PS3 (continuation and + select) prompts support respectively: as command substitution is not + performed in these shells for these prompts they are updated once each time + PS1 prompt is displayed which may be slow. + + It is also known that while PS2 and PS3 update is triggered at PS1 update it + is *actually performed* only *next* time PS1 is displayed which means that + PS2 and PS3 prompts will be outdated and may be incorrect for this reason. + + Without these variables PS2 and PS3 prompts will be set once at startup. + This only touches mksh users: busybox and dash both have no such problem. + .. warning:: Job count is using some weird hack that uses signals and temporary files for interprocess communication. It may be wrong sometimes. Not the case in mksh. diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index 93670555..e44d9da2 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -39,6 +39,16 @@ _powerline_init_tmux_support() { fi } +_powerline_local_prompt() { + # Arguments: side, renderer_module arg, last_exit_code, jobnum, local theme + $POWERLINE_COMMAND shell $1 \ + $2 \ + --last_exit_code=$3 \ + --jobnum=$4 \ + --renderer_arg="client_id=$$" \ + --renderer_arg="local_theme=$5" +} + _powerline_prompt() { # Arguments: side, last_exit_code, jobnum $POWERLINE_COMMAND shell $1 \ @@ -53,6 +63,12 @@ _powerline_set_prompt() { local last_exit_code=$? local jobnum="$(jobs -p|wc -l)" PS1="$(_powerline_prompt aboveleft $last_exit_code $jobnum)" + if test -n "$POWERLINE_SHELL_CONTINUATION$POWERLINE_BASH_CONTINUATION" ; then + PS2="$(_powerline_local_prompt left -rbash_prompt $last_exit_code $jobnum continuation)" + fi + if test -n "$POWERLINE_SHELL_SELECT$POWERLINE_BASH_SELECT" ; then + PS3="$(_powerline_local_prompt left '' $last_exit_code $jobnum select)" + fi return $last_exit_code } @@ -63,6 +79,8 @@ _powerline_setup_prompt() { fi test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" || PROMPT_COMMAND=$'_powerline_set_prompt\n'"${PROMPT_COMMAND}" + PS2="$(_powerline_local_prompt left -rbash_prompt 0 0 continuation)" + PS3="$(_powerline_local_prompt left '' 0 0 select)" } if test -z "${POWERLINE_CONFIG}" ; then diff --git a/powerline/bindings/shell/powerline.sh b/powerline/bindings/shell/powerline.sh index d197c5be..3fc2b434 100644 --- a/powerline/bindings/shell/powerline.sh +++ b/powerline/bindings/shell/powerline.sh @@ -41,6 +41,8 @@ _powerline_set_append_trap() { if echo "$_powerline_traps" | grep -cm1 $2'$' >/dev/null ; then _powerline_traps="$(echo "$_powerline_traps" | sed "s/ $2/'\\n$1' $2/")" eval "$_powerline_traps" + else + trap "$1" $2 fi } else @@ -131,6 +133,17 @@ _powerline_set_jobs() { _powerline_set_jobs } +_powerline_local_prompt() { + # Arguments: side, exit_code, local theme + _powerline_set_jobs + $POWERLINE_COMMAND shell $1 \ + $_POWERLINE_RENDERER_ARG \ + --renderer_arg="client_id=$$" \ + --last_exit_code=$2 \ + --jobnum=$_POWERLINE_JOBS \ + --renderer_arg="local_theme=$3" +} + _powerline_prompt() { # Arguments: side, exit_code _powerline_set_jobs @@ -140,6 +153,37 @@ _powerline_prompt() { --renderer_arg="client_id=$$" \ --last_exit_code=$2 \ --jobnum=$_POWERLINE_JOBS + _powerline_update_psN +} + +_powerline_setup_psN() { + case "$1" in + mksh|ksh|bash) + _POWERLINE_PID=$$ + _powerline_update_psN() { + kill -USR1 $_POWERLINE_PID + } + # No command substitution in PS2 and PS3 + _powerline_set_psN() { + if test -n "$POWERLINE_SHELL_CONTINUATION" ; then + PS2="$(_powerline_local_prompt left $? continuation)" + fi + if test -n "$POWERLINE_SHELL_SELECT" ; then + PS3="$(_powerline_local_prompt left $? select)" + fi + } + _powerline_append_trap '_powerline_set_psN' USR1 + _powerline_set_psN + ;; + bb|ash|dash) + _powerline_update_psN() { + # Do nothing + return + } + PS2='$(_powerline_local_prompt left $? continuation)' + # No select support + ;; + esac } _powerline_setup_prompt() { @@ -149,6 +193,9 @@ _powerline_setup_prompt() { _powerline_set_command "$@" _powerline_set_renderer_arg "$@" PS1='$(_powerline_prompt aboveleft $?)' + PS2="$(_powerline_local_prompt left 0 continuation)" + PS3="$(_powerline_local_prompt left 0 select)" + _powerline_setup_psN "$@" } _powerline_init_tmux_support() { diff --git a/powerline/renderers/shell.py b/powerline/renderers/shell.py index 360acafc..fdffaa25 100644 --- a/powerline/renderers/shell.py +++ b/powerline/renderers/shell.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals, division, print_function from powerline.renderer import Renderer +from powerline.theme import Theme from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE @@ -120,5 +121,19 @@ class ShellRenderer(Renderer): r = '\033P' + r.replace('\033', '\033\033') + '\033\\' return self.escape_hl_start + r + self.escape_hl_end + def get_theme(self, matcher_info): + if not matcher_info: + return self.theme + match = self.local_themes[matcher_info] + try: + return match['theme'] + except KeyError: + match['theme'] = Theme( + theme_config=match['config'], + main_theme_config=self.theme_config, + **self.theme_kwargs + ) + return match['theme'] + renderer = ShellRenderer diff --git a/powerline/renderers/zsh_prompt.py b/powerline/renderers/zsh_prompt.py index b0bcede6..47e76cc3 100644 --- a/powerline/renderers/zsh_prompt.py +++ b/powerline/renderers/zsh_prompt.py @@ -3,7 +3,6 @@ from __future__ import absolute_import, unicode_literals from powerline.renderers.shell import ShellRenderer -from powerline.theme import Theme class ZshPromptRenderer(ShellRenderer): @@ -14,19 +13,5 @@ class ZshPromptRenderer(ShellRenderer): character_translations = ShellRenderer.character_translations.copy() character_translations[ord('%')] = '%%' - def get_theme(self, matcher_info): - if not matcher_info: - return self.theme - match = self.local_themes[matcher_info] - try: - return match['theme'] - except KeyError: - match['theme'] = Theme( - theme_config=match['config'], - main_theme_config=self.theme_config, - **self.theme_kwargs - ) - return match['theme'] - renderer = ZshPromptRenderer diff --git a/powerline/segments/shell.py b/powerline/segments/shell.py index 8afc20a1..a13fa09f 100644 --- a/powerline/segments/shell.py +++ b/powerline/segments/shell.py @@ -89,7 +89,11 @@ def continuation(pl, segment_info, omit_cmdsubst=True, right_align=False, rename Highlight groups used: ``continuation``, ``continuation:current``. ''' if not segment_info.get('parser_state'): - return None + return [{ + 'contents': '', + 'width': 'auto', + 'highlight_group': ['continuation:current', 'continuation'], + }] ret = [] for state in segment_info['parser_state'].split(): @@ -97,7 +101,7 @@ def continuation(pl, segment_info, omit_cmdsubst=True, right_align=False, rename if state: ret.append({ 'contents': state, - 'highlight_group': 'continuation', + 'highlight_group': ['continuation'], 'draw_inner_divider': True, }) @@ -111,8 +115,8 @@ def continuation(pl, segment_info, omit_cmdsubst=True, right_align=False, rename if right_align: ret[0].update(width='auto', align='r') - ret[-1]['highlight_group'] = 'continuation:current' + ret[-1]['highlight_group'] = ['continuation:current', 'continuation'] else: - ret[-1].update(width='auto', align='l', highlight_group='continuation:current') + ret[-1].update(width='auto', align='l', highlight_group=['continuation:current', 'continuation']) return ret diff --git a/tests/test_segments.py b/tests/test_segments.py index 345a6ccc..107d982c 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -62,13 +62,17 @@ class TestShell(TestCase): def test_continuation(self): pl = Pl() - self.assertEqual(shell.continuation(pl=pl, segment_info={}), None) + self.assertEqual(shell.continuation(pl=pl, segment_info={}), [{ + 'contents': '', + 'width': 'auto', + 'highlight_group': ['continuation:current', 'continuation'], + }]) segment_info = {'parser_state': 'if cmdsubst'} self.assertEqual(shell.continuation(pl=pl, segment_info=segment_info), [ { 'contents': 'if', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'l', }, @@ -77,7 +81,7 @@ class TestShell(TestCase): { 'contents': 'if', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'r', }, @@ -86,12 +90,12 @@ class TestShell(TestCase): { 'contents': 'if', 'draw_inner_divider': True, - 'highlight_group': 'continuation', + 'highlight_group': ['continuation'], }, { 'contents': 'cmdsubst', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'l', }, @@ -100,21 +104,21 @@ class TestShell(TestCase): { 'contents': 'if', 'draw_inner_divider': True, - 'highlight_group': 'continuation', + 'highlight_group': ['continuation'], 'width': 'auto', 'align': 'r', }, { 'contents': 'cmdsubst', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], }, ]) self.assertEqual(shell.continuation(pl=pl, segment_info=segment_info, omit_cmdsubst=True, right_align=True), [ { 'contents': 'if', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'r', }, @@ -123,7 +127,7 @@ class TestShell(TestCase): { 'contents': 'IF', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'r', }, @@ -131,7 +135,7 @@ class TestShell(TestCase): self.assertEqual(shell.continuation(pl=pl, segment_info=segment_info, omit_cmdsubst=True, right_align=True, renames={'if': None}), [ { 'contents': '', - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'r', }, @@ -141,17 +145,17 @@ class TestShell(TestCase): { 'contents': 'then', 'draw_inner_divider': True, - 'highlight_group': 'continuation', + 'highlight_group': ['continuation'], }, { 'contents': 'then', 'draw_inner_divider': True, - 'highlight_group': 'continuation', + 'highlight_group': ['continuation'], }, { 'contents': 'then', 'draw_inner_divider': True, - 'highlight_group': 'continuation:current', + 'highlight_group': ['continuation:current', 'continuation'], 'width': 'auto', 'align': 'l', }, diff --git a/tests/test_shells/bash.daemon.ok b/tests/test_shells/bash.daemon.ok new file mode 100644 index 00000000..1354b641 --- /dev/null +++ b/tests/test_shells/bash.daemon.ok @@ -0,0 +1,28 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +[1] PID +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1]+ Terminated bgscript.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" + USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo ' +                                     abc +                                     def +                                     ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/bash.nodaemon.ok b/tests/test_shells/bash.nodaemon.ok new file mode 100644 index 00000000..cb0f6b6d --- /dev/null +++ b/tests/test_shells/bash.nodaemon.ok @@ -0,0 +1,28 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +[1] PID +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1]+ Terminated bgscript.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" + USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo ' +   abc +   def +   ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/bash.ok b/tests/test_shells/bash.ok deleted file mode 100644 index 0ee4e9b6..00000000 --- a/tests/test_shells/bash.ok +++ /dev/null @@ -1,18 +0,0 @@ -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh -[1] PID -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s -[1]+ Terminated bgscript.sh -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/busybox.daemon.ok b/tests/test_shells/busybox.daemon.ok new file mode 100644 index 00000000..4a5bf072 --- /dev/null +++ b/tests/test_shells/busybox.daemon.ok @@ -0,0 +1,27 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1]+ Terminated bgscript.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" + USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo ' +                                     abc +                                     def +                                     ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/busybox.nodaemon.ok b/tests/test_shells/busybox.nodaemon.ok new file mode 100644 index 00000000..1f6f7449 --- /dev/null +++ b/tests/test_shells/busybox.nodaemon.ok @@ -0,0 +1,27 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1]+ Terminated bgscript.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" + USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo ' +   abc +   def +   ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/busybox.ok b/tests/test_shells/busybox.ok deleted file mode 100644 index 760d7d03..00000000 --- a/tests/test_shells/busybox.ok +++ /dev/null @@ -1,17 +0,0 @@ -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s -[1]+ Terminated bgscript.sh -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  cd "$DIR1" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/dash.daemon.ok b/tests/test_shells/dash.daemon.ok new file mode 100644 index 00000000..bbf3de59 --- /dev/null +++ b/tests/test_shells/dash.daemon.ok @@ -0,0 +1,26 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1   USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo ' +                                     abc +                                     def +                                     ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/dash.nodaemon.ok b/tests/test_shells/dash.nodaemon.ok new file mode 100644 index 00000000..3a81cfcc --- /dev/null +++ b/tests/test_shells/dash.nodaemon.ok @@ -0,0 +1,26 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1   USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo ' +   abc +   def +   ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/dash.ok b/tests/test_shells/dash.ok deleted file mode 100644 index 2ad24b25..00000000 --- a/tests/test_shells/dash.ok +++ /dev/null @@ -1,17 +0,0 @@ -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s -[1] + Terminated bgscript.sh -cd "$DIR1" -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1    HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/input.bash b/tests/test_shells/input.bash index 47042cf9..e2d69dfa 100644 --- a/tests/test_shells/input.bash +++ b/tests/test_shells/input.bash @@ -11,6 +11,12 @@ VIRTUAL_ENV= bgscript.sh & waitpid.sh false kill `cat pid` ; sleep 1s +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +echo ' +abc +def +' cd "$DIR1" cd ../"$DIR2" cd ../'\[\]' diff --git a/tests/test_shells/input.busybox b/tests/test_shells/input.busybox index d5b11b12..b5e94004 100644 --- a/tests/test_shells/input.busybox +++ b/tests/test_shells/input.busybox @@ -11,6 +11,12 @@ VIRTUAL_ENV= bgscript.sh & waitpid.sh false kill `cat pid` ; sleep 1s +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +echo ' +abc +def +' cd "$DIR1" cd ../"$DIR2" cd ../'\[\]' diff --git a/tests/test_shells/input.dash b/tests/test_shells/input.dash index d5b11b12..b5e94004 100644 --- a/tests/test_shells/input.dash +++ b/tests/test_shells/input.dash @@ -11,6 +11,12 @@ VIRTUAL_ENV= bgscript.sh & waitpid.sh false kill `cat pid` ; sleep 1s +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +echo ' +abc +def +' cd "$DIR1" cd ../"$DIR2" cd ../'\[\]' diff --git a/tests/test_shells/input.mksh b/tests/test_shells/input.mksh index 0b0b4904..4ac08441 100644 --- a/tests/test_shells/input.mksh +++ b/tests/test_shells/input.mksh @@ -11,6 +11,13 @@ VIRTUAL_ENV= bgscript.sh & waitpid.sh false kill `cat pid` ; sleep 1 +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +echo -n +echo ' +abc +def +' cd "$DIR1" cd ../"$DIR2" cd ../'\[\]' diff --git a/tests/test_shells/mksh.daemon.ok b/tests/test_shells/mksh.daemon.ok new file mode 100644 index 00000000..569a62e2 --- /dev/null +++ b/tests/test_shells/mksh.daemon.ok @@ -0,0 +1,30 @@ + +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +[1] PID +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1 +[1] + Terminated bash -c ... +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" + USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo -n +  BRANCH  ⋯  tests  shell  3rd  echo ' +                                     abc +                                     def +                                     ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/mksh.nodaemon.ok b/tests/test_shells/mksh.nodaemon.ok new file mode 100644 index 00000000..a6d94036 --- /dev/null +++ b/tests/test_shells/mksh.nodaemon.ok @@ -0,0 +1,30 @@ + +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh +[1] PID +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1 +[1] + Terminated bash -c ... +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.display=false" + USER   BRANCH  ⋯  tests  shell  3rd  POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.user.display=false" +  BRANCH  ⋯  tests  shell  3rd  echo -n +  BRANCH  ⋯  tests  shell  3rd  echo ' +   abc +   def +   ' + +abc +def + +  BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/mksh.ok b/tests/test_shells/mksh.ok deleted file mode 100644 index 4770aff1..00000000 --- a/tests/test_shells/mksh.ok +++ /dev/null @@ -1,19 +0,0 @@ - -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bgscript.sh & waitpid.sh -[1] PID -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1 -[1] + Terminated bash -c ... -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index dd12f829..6866dfc1 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -58,4 +58,9 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: # command, in travis it is truncated just after `true`. if line.startswith('[1] + Terminated'): line = '[1] + Terminated bash -c ...\n' + elif shell == 'dash': + # Position of this line is not stable: it may go both before and + # after the next line + if line.startswith('[1] + Terminated'): + continue W.write(line) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 6e12d257..b9b46529 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -22,6 +22,11 @@ run() { if test "x$SH" = "xfish" ; then local_path="${local_path}:/usr/bin:/bin" fi + if test $TEST_TYPE = daemon ; then + local additional_prompts=1 + else + local additional_prompts= + fi env -i \ PATH="$local_path" \ TERM="${TERM}" \ @@ -33,6 +38,8 @@ run() { DIR2="${DIR2}" \ XDG_CONFIG_HOME="$PWD/tests/shell/fish_home" \ IPYTHONDIR="$PWD/tests/shell/ipython_home" \ + POWERLINE_SHELL_CONTINUATION=$additional_prompts \ + POWERLINE_SHELL_SELECT=$additional_prompts \ "$@" } @@ -156,6 +163,9 @@ ln -s "$(which cut)" tests/shell/path ln -s "$(which bc)" tests/shell/path ln -s "$(which expr)" tests/shell/path ln -s "$(which mktemp)" tests/shell/path +ln -s "$(which grep)" tests/shell/path +ln -s "$(which sed)" tests/shell/path +ln -s "$(which rm)" tests/shell/path ln -s ../../test_shells/bgscript.sh tests/shell/path ln -s ../../test_shells/waitpid.sh tests/shell/path for pexe in powerline powerline-config ; do @@ -169,7 +179,7 @@ for pexe in powerline powerline-config ; do fi done -for exe in bash zsh bb busybox fish tcsh mksh dash ipython ; do +for exe in bash zsh busybox fish tcsh mksh dash ipython ; do if which $exe >/dev/null ; then ln -s "$(which $exe)" tests/shell/path fi @@ -177,7 +187,7 @@ done unset ENV -if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || test "x${ONLY_SHELL}" = xbb ; then +if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || test "x${ONLY_SHELL}" = xbusybox ; then powerline-daemon -k || true sleep 1s