Skip to content

Instantly share code, notes, and snippets.

@zeisler
Last active January 6, 2017 00:59
Show Gist options
  • Save zeisler/81d9916ef776e25c0c7968df52bc61a6 to your computer and use it in GitHub Desktop.
Save zeisler/81d9916ef776e25c0c7968df52bc61a6 to your computer and use it in GitHub Desktop.
Add Travis status to prompt, given travis command exists
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%}$(travis_status)$(git_prompt_info)'
function travis_status_dir {
GIT_ROOT=`git rev-parse --show-toplevel`
echo "${GIT_ROOT}/tmp/.travis"
}
function travis_status_file {
GIT_SHA=`git rev-parse HEAD`
DIR=`travis_status_dir`
echo "${DIR}/${GIT_SHA}.status"
}
function git_root {
echo `git rev-parse --show-toplevel`
}
function travis_status {
GIT_ROOT=`git_root`
if [ ! -f "${GIT_ROOT}/.travis.yml" ]; then
return
fi
if [ ! -d `travis_status_dir` ]; then
mkdir `travis_status_dir`
fi
if [ ! -f `travis_status_file` ]; then
save_travis_status &>/dev/null &
echo " \u25CB"
else
TRAVIS_FILE=`travis_status_file`
RESULT=`tail -1 ${TRAVIS_FILE}`
if [ "$RESULT" != "passed" ] && [ "$RESULT" != "failed" ] && [ "$RESULT" != "waiting" ]; then
save_travis_status &>/dev/null &
fi
if [ "$RESULT" = "passed" ]; then
echo " \e[32m\u25CF\e[0m"
elif [ "$RESULT" = "started" ]; then
echo " \e[33m\u25CF\e[0m"
elif [ "$RESULT" = "failed" ]; then
echo " \e[31m\u25CF\e[0m"
elif [ "$RESULT" = "waiting" ]; then
echo " \e[33m\u25CB\e[0m"
else
echo " \e[33m${RESULT}\e[0m"
fi
fi
}
function save_travis_status {
TRAVIS_FILE=`travis_status_file`
LINE_COUNT=`wc -l ${TRAVIS_FILE}`
if [[ LINE_COUNT -lt 2 ]]; then
echo "waiting" >> `travis_status_file`
fi
echo `travis status` >> `travis_status_file`
}
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%} git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment