Merge pull request #773 from ZyX-I/tcsh

Add tcsh support

Fixes #762.
This commit is contained in:
ZyX-I 2014-01-26 12:24:48 -08:00
commit ac04a1806f
12 changed files with 93 additions and 8 deletions

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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 ../'\[\]'

View File

@ -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"

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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)

16
tests/test_shells/tcsh.ok Normal file
View File

@ -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`  

View File

@ -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

View File

@ -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 ../'\[\]'