diff --git a/powerline/bindings/tcsh/powerline.tcsh b/powerline/bindings/tcsh/powerline.tcsh new file mode 100644 index 00000000..48566318 --- /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 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 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/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 new file mode 100644 index 00000000..cf87b8f9 --- /dev/null +++ b/tests/test_shells/tcsh.ok @@ -0,0 +1,16 @@ +  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`   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 ../'\[\]'