From 3ecbeb8c5b9b555f320001c162b9975d8a86acad Mon Sep 17 00:00:00 2001 From: ZyX Date: Thu, 23 Jan 2014 21:44:11 +0400 Subject: [PATCH 1/5] Add powerline.tcsh Ref #762 --- powerline/bindings/tcsh/powerline.tcsh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 powerline/bindings/tcsh/powerline.tcsh diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh new file mode 100644 index 00000000..aa81d011 --- /dev/null +++ b/powerline/bindings/tcsh/powerline.tcsh @@ -0,0 +1,21 @@ +# http://unix.stackexchange.com/questions/4650/determining-path-to-sourced-shell-script: +# > In tcsh, $_ at the beginning of the script will contain the location if the +# > file was sourced and $0 contains it if it was run. +# +# Guess this relies on `$_` being set as to last argument to previous command +# which must be `.` or `source` in this case +set POWERLINE_SOURCED=($_) +if ! $?POWERLINE_COMMAND then + if ( { which powerline-client > /dev/null } ) then + setenv POWERLINE_COMMAND powerline-client + else if ( { which powerline > /dev/null } ) then + setenv POWERLINE_COMMAND powerline + else + setenv POWERLINE_COMMAND $POWERLINE_SOURCED:h:h:h:h:q/scripts/powerline + endif +endif +alias _powerline_tmux_set_pwd 'if $?TMUX tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if $?TMUX tmux refresh -S' +alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r zsh_prompt --last_exit_code=$?`"' +alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r zsh_prompt --last_exit_code=$?`"' +alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd" +alias precmd "`alias precmd` ; _powerline_set_prompt ; _powerline_set_rprompt" From a2e11ef94f3662cc123721987bb823253b082066 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Jan 2014 23:39:25 +0400 Subject: [PATCH 2/5] Add space to rprompt According to tcsh documentation `%{%}` must not be the last segment. Note: this means that right prompt has *two* characters between its end and terminal emulator border. --- powerline/bindings/tcsh/powerline.tcsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh index aa81d011..d60b46d1 100644 --- a/powerline/bindings/tcsh/powerline.tcsh +++ b/powerline/bindings/tcsh/powerline.tcsh @@ -16,6 +16,6 @@ if ! $?POWERLINE_COMMAND then endif alias _powerline_tmux_set_pwd 'if $?TMUX tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if $?TMUX tmux refresh -S' alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r zsh_prompt --last_exit_code=$?`"' -alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r zsh_prompt --last_exit_code=$?`"' +alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r zsh_prompt --last_exit_code=$?` "' alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd" alias precmd "`alias precmd` ; _powerline_set_prompt ; _powerline_set_rprompt" From 219b81d23daebee389faf78cea002311420975aa Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 27 Jan 2014 00:00:25 +0400 Subject: [PATCH 3/5] Fix tcsh escaping --- powerline/bindings/tcsh/powerline.tcsh | 4 ++-- powerline/renderers/tcsh_prompt.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 powerline/renderers/tcsh_prompt.py diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh index d60b46d1..48566318 100644 --- a/powerline/bindings/tcsh/powerline.tcsh +++ b/powerline/bindings/tcsh/powerline.tcsh @@ -15,7 +15,7 @@ if ! $?POWERLINE_COMMAND then endif endif alias _powerline_tmux_set_pwd 'if $?TMUX tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if $?TMUX tmux refresh -S' -alias _powerline_set_prompt 'set prompt="`$POWERLINE_COMMAND shell left -r zsh_prompt --last_exit_code=$?`"' -alias _powerline_set_rprompt 'set rprompt="`$POWERLINE_COMMAND shell right -r zsh_prompt --last_exit_code=$?` "' +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" diff --git a/powerline/renderers/tcsh_prompt.py b/powerline/renderers/tcsh_prompt.py new file mode 100644 index 00000000..adbb91c9 --- /dev/null +++ b/powerline/renderers/tcsh_prompt.py @@ -0,0 +1,16 @@ +# vim:fileencoding=utf-8:noet + +from __future__ import absolute_import, unicode_literals + +from powerline.renderers.zsh_prompt import ZshPromptRenderer + + +class TcshPromptRenderer(ZshPromptRenderer): + '''Powerline tcsh prompt segment renderer.''' + character_translations = ZshPromptRenderer.character_translations.copy() + character_translations[ord('%')] = '%%' + character_translations[ord('\\')] = '\\\\' + character_translations[ord('^')] = '\\^' + + +renderer = TcshPromptRenderer From fe99e252e9d9d2116f22ad148c6aadbfc01d2880 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 26 Jan 2014 23:52:06 +0400 Subject: [PATCH 4/5] Add tcsh tests --- tests/install.sh | 2 +- tests/test_shells/bash.ok | 4 ++-- tests/test_shells/input.bash | 2 +- tests/test_shells/input.fish | 2 +- tests/test_shells/input.tcsh | 21 +++++++++++++++++++++ tests/test_shells/input.zsh | 2 +- tests/test_shells/tcsh.ok | 19 +++++++++++++++++++ tests/test_shells/test.sh | 4 ++++ tests/test_shells/zsh.ok | 4 ++-- 9 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 tests/test_shells/input.tcsh create mode 100644 tests/test_shells/tcsh.ok diff --git a/tests/install.sh b/tests/install.sh index a448371f..ab666a81 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -9,7 +9,7 @@ if python -c 'import sys; sys.exit(1 * (sys.version_info[0] != 2))' ; then pip install unittest2 argparse fi fi -sudo apt-get install -qq screen zsh +sudo apt-get install -qq screen zsh tcsh # Travis has too outdated fish. It cannot be used for tests. # sudo apt-get install fish true diff --git a/tests/test_shells/bash.ok b/tests/test_shells/bash.ok index b5026d25..34ec242f 100644 --- a/tests/test_shells/bash.ok +++ b/tests/test_shells/bash.ok @@ -2,11 +2,11 @@   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  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & [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 bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +[1]+ Terminated bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done'   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1"   HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2"   HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' diff --git a/tests/test_shells/input.bash b/tests/test_shells/input.bash index e9f0d8ab..3a95d3a1 100644 --- a/tests/test_shells/input.bash +++ b/tests/test_shells/input.bash @@ -7,7 +7,7 @@ cd .git cd .. VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" VIRTUAL_ENV= -bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & false kill `cat pid` ; sleep 1s cd "$DIR1" diff --git a/tests/test_shells/input.fish b/tests/test_shells/input.fish index f6dcc4fc..afb3df3b 100644 --- a/tests/test_shells/input.fish +++ b/tests/test_shells/input.fish @@ -8,7 +8,7 @@ cd .git cd .. set VIRTUAL_ENV "$HOME/.virtenvs/some-virtual-environment" set VIRTUAL_ENV -bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & false kill (cat pid) ; sleep 1s cd "$DIR1" diff --git a/tests/test_shells/input.tcsh b/tests/test_shells/input.tcsh new file mode 100644 index 00000000..4d48a465 --- /dev/null +++ b/tests/test_shells/input.tcsh @@ -0,0 +1,21 @@ +setenv POWERLINE_COMMAND $PWD:q/scripts/powerline" -p "$PWD:q/powerline/config_files" -t default_leftonly.segment_data.hostname.args.only_if_ssh=false -c ext.shell.theme=default_leftonly" +unsetenv VIRTUAL_ENV +source powerline/bindings/tcsh/powerline.tcsh ; cd tests/shell/3rd +cd .git +cd .. +setenv VIRTUAL_ENV $HOME:q"/.virtenvs/some-virtual-environment" +unsetenv VIRTUAL_ENV +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +false # Warning: currently tcsh bindings do not support job count +kill `cat pid` ; sleep 1s +cd $DIR1:q +cd ../$DIR2:q +cd ../'\[\]' +cd ../'%%' +cd ../'#[bold]' +cd ../'(echo)' +cd ../'$(echo)' +cd ../'`echo`' +false +true is the last line +exit diff --git a/tests/test_shells/input.zsh b/tests/test_shells/input.zsh index 8cd28d54..1b3020a5 100644 --- a/tests/test_shells/input.zsh +++ b/tests/test_shells/input.zsh @@ -8,7 +8,7 @@ cd .git cd .. VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" VIRTUAL_ENV= -bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & false kill `cat pid` ; sleep 1s cd "$DIR1" diff --git a/tests/test_shells/tcsh.ok b/tests/test_shells/tcsh.ok new file mode 100644 index 00000000..cea0c31a --- /dev/null +++ b/tests/test_shells/tcsh.ok @@ -0,0 +1,19 @@ + +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git    cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    setenv VIRTUAL_ENV $HOME:q"/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd    unsetenv VIRTUAL_ENV +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +[1] PID +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    false # Warning: currently tcsh bindings do not support job count +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1    kill `cat pid` ; sleep 1s +[1] + Terminated bash -c echo $$>pid ; while true ; do sleep 0.1s ; done +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    cd $DIR1:q +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m    cd ../$DIR2:q +  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/test.sh b/tests/test_shells/test.sh index c38d13c4..9e9c370b 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -86,5 +86,9 @@ if ! run_test fish -i ; then FAILED=1 fi +if ! run_test tcsh -f -i ; then + FAILED=1 +fi + test "x$ONLY_SHELL" = "x" && rm -r tests/shell exit $FAILED diff --git a/tests/test_shells/zsh.ok b/tests/test_shells/zsh.ok index dbc5e17b..13daf829 100644 --- a/tests/test_shells/zsh.ok +++ b/tests/test_shells/zsh.ok @@ -3,11 +3,11 @@   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  bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" & +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & [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 bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +[1] + terminated bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done'   HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1"   HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2"   HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' From c648178be0eb07ae431ba5f9a9502e857920a8ab Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 27 Jan 2014 00:22:38 +0400 Subject: [PATCH 5/5] Strip anything but prompt from tcsh tests There are some problems with a number of spaces on travis: it differs. Cannot use the same code as for fish because output looks like {prompt}{spaces}^[0m ^[[{number}D and both `{spaces}` and `{number}` differ on my machine and in travis. --- tests/test_shells/postproc.py | 7 +++++++ tests/test_shells/tcsh.ok | 35 ++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index 9696b5b9..2da1fbc7 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -41,4 +41,11 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: line = line[start : end+4] + '\n' except ValueError: line = '' + elif shell == 'tcsh': + try: + start = line.index('\033[0;') + end = line.index(' ', start) + line = line[start : end] + '\033[0m\n' + except ValueError: + line = '' W.write(line) diff --git a/tests/test_shells/tcsh.ok b/tests/test_shells/tcsh.ok index cea0c31a..cf87b8f9 100644 --- a/tests/test_shells/tcsh.ok +++ b/tests/test_shells/tcsh.ok @@ -1,19 +1,16 @@ - -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    cd .git -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git    cd .. -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    setenv VIRTUAL_ENV $HOME:q"/.virtenvs/some-virtual-environment" -  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd    unsetenv VIRTUAL_ENV -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & -[1] PID -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    false # Warning: currently tcsh bindings do not support job count -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1    kill `cat pid` ; sleep 1s -[1] + Terminated bash -c echo $$>pid ; while true ; do sleep 0.1s ; done -  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd    cd $DIR1:q -  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m    cd ../$DIR2:q -  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 +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1   +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)   +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo` 