Merge pull request #696 from ZyX-I/fish

Add powerline/bindings/fish/powerline.fish
This commit is contained in:
ZyX-I 2014-01-23 06:36:58 -08:00
commit 79c4d37814
7 changed files with 123 additions and 25 deletions

View File

@ -150,6 +150,16 @@ absolute path to your Powerline installation directory:
. {repository_root}/powerline/bindings/zsh/powerline.zsh
Fish prompt
^^^^^^^^^^^
Add the following line to your :file:`config.fish`, where ``{repository_root}``
is the absolute path to your Powerline installation directory:
.. code-block:: bash
. {repository_root}/powerline/bindings/fish/powerline.fish
Tmux statusline
---------------

View File

@ -0,0 +1,36 @@
function powerline
if test -z "$POWERLINE_COMMAND"
if which powerline-client >/dev/null
set -g -x POWERLINE_COMMAND powerline-client
else
set -g -x POWERLINE_COMMAND 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
function _powerline_tmux_setenv
if test -n "$TMUX"
tmux setenv -g TMUX_$argv[1]_(tmux display -p "#D" | tr -d "%") "$argv[2]"
tmux refresh -S
end
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
powerline

View File

@ -9,5 +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 zsh screen
sudo apt-get install -qq screen zsh
# Travis has too outdated fish. It cannot be used for tests.
# sudo apt-get install fish
true

View File

@ -0,0 +1,8 @@
  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  1  
  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  
  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  

View File

@ -0,0 +1,15 @@
set POWERLINE_COMMAND "$PWD/scripts/powerline -p $PWD/powerline/config_files"
set POWERLINE_COMMAND "$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false"
set POWERLINE_COMMAND "$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly"
set VIRTUAL_ENV
. powerline/bindings/fish/powerline.fish ; cd tests/shell/3rd
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" &
false
kill (cat pid) ; sleep 1s
false
true is the last line
exit

View File

@ -12,6 +12,8 @@ fname = sys.argv[1]
new_fname = fname + '.new'
pid_fname = 'tests/shell/3rd/pid'
shell = sys.argv[2]
with open(pid_fname, 'r') as P:
pid = P.read().strip()
hostname = socket.gethostname()
@ -20,7 +22,7 @@ user = os.environ['USER']
with codecs.open(fname, 'r', encoding='utf-8') as R:
with codecs.open(new_fname, 'w', encoding='utf-8') as W:
found_cd = False
for line in R:
for line in (R if shell != 'fish' else R.read().split('\n')):
if not found_cd:
found_cd = ('cd tests/shell/3rd' in line)
continue
@ -32,6 +34,13 @@ with codecs.open(fname, 'r', encoding='utf-8') as R:
line = line.replace(hostname, 'HOSTNAME')
line = line.replace(user, 'USER')
line = line.replace(pid, 'PID')
if shell == 'fish':
try:
start = line.index('\033[0;')
end = line.index('\033[0m', start)
line = line[start : end+4] + '\n'
except ValueError:
line = ''
W.write(line)
os.rename(new_fname, fname)

View File

@ -1,30 +1,30 @@
#!/bin/sh
FAILED=0
if [ "$(echo '\e')" != '\e' ] ; then
safe_echo() {
echo -E "$@"
}
else
safe_echo() {
echo "$@"
}
fi
ONLY_SHELL="$1"
check_screen_log() {
diff -u tests/test_shells/${1}.ok tests/shell/screen.log
# Explicit is better then implicit
return $?
if test -e tests/test_shells/${1}.ok ; then
diff -u tests/test_shells/${1}.ok tests/shell/screen.log
return $?
else
cat tests/shell/screen.log
return 1
fi
}
run_test() {
SH="$1"
SESNAME="powerline-shell-test-$$"
SESNAME="powerline-shell-test-${SH}-$$"
test "x$ONLY_SHELL" = "x" || test "x$ONLY_SHELL" = "x$SH" || return 0
which "${SH}" || return 0
screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \
env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "$@"
screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH
# Wait for screen to initialize
sleep 0.3s
sleep 1s
screen -S "$SESNAME" -p 0 -X width 300 1
screen -S "$SESNAME" -p 0 -X logfile tests/shell/screen.log
screen -S "$SESNAME" -p 0 -X paste a
@ -33,32 +33,50 @@ run_test() {
while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do
sleep 0.1s
done
./tests/test_shells/postproc.py tests/shell/screen.log
cp tests/shell/screen.log tests/shell/${SH}.full.log
./tests/test_shells/postproc.py tests/shell/screen.log ${SH}
cp tests/shell/screen.log tests/shell/${SH}.log
if ! check_screen_log ${SH} ; then
echo '____________________________________________________________'
# Repeat the diff to make it better viewable in travis output
echo "Diff (cat -v):"
echo '============================================================'
check_screen_log ${SH} | cat -v
echo '____________________________________________________________'
echo "Failed ${SH}. Full output:"
echo '============================================================'
cat tests/shell/${SH}.full.log
echo '____________________________________________________________'
echo "Full output (cat -v):"
echo '============================================================'
cat -v tests/shell/${SH}.full.log
echo '____________________________________________________________'
${SH} --version
rm tests/shell/screen.log
return 1
fi
rm tests/shell/screen.log
return 0
}
test -d tests/shell && rm -r tests/shell
mkdir tests/shell
git init tests/shell/3rd
git --git-dir=tests/shell/3rd/.git checkout -b BRANCH
if ! run_test bash --norc --noprofile -i ; then
echo "Failed bash"
FAILED=1
fi
cp tests/shell/screen.log tests/bash.log
rm tests/shell/screen.log
if ! run_test zsh -f -i ; then
echo "Failed zsh"
FAILED=1
fi
cp tests/shell/screen.log tests/zsh.log
rm tests/shell/screen.log
rm -r tests/shell
mkdir tests/shell/fish_home
export XDG_CONFIG_HOME="$PWD/tests/shell/fish_home"
if ! run_test fish -i ; then
FAILED=1
fi
test "x$ONLY_SHELL" = "x" && rm -r tests/shell
exit $FAILED