Skip to content

Commit

Permalink
Merge pull request #1 from molovo/add_ci_status_indicator
Browse files Browse the repository at this point in the history
Add CI status to RPROMPT when FILTHY_SHOW_CI_STATUS is set.
  • Loading branch information
molovo committed Jan 30, 2017
2 parents 608e505 + d959d4a commit f1f1efe
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions filthy.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,41 @@ prompt_filthy_rprompt() {
# Print the repository status
branch=$(prompt_filthy_git_branch)
repo_status=$(prompt_filthy_git_repo_status)
print "${repo_status} ${branch}"
ci_status=$(prompt_filthy_ci_status)
print "${branch}${repo_status}${ci_status}"
fi
}

prompt_filthy_ci_status() {
local state

[[ $FILTHY_SHOW_CI_STATUS -eq 0 ]] && return

if command type hub >/dev/null 2>&1; then
state=$(hub ci-status 2>&1)
case $state in
success )
print ' %F{green}●%f'
;;
pending )
print ' %F{yellow}○%f'
;;
failure )
print ' %F{red}●%f'
;;
error )
print ' %F{red}‼%f'
;;
'no status' )
print ' %F{242}○%f'
;;
esac
fi

print $cached_ci_state
ci_state_last_update_time=$((EPOCHREALTIME*1000))
}

prompt_filthy_git_repo_status() {
# Do a fetch asynchronously
git fetch > /dev/null 2>&1 &!
Expand All @@ -161,7 +192,10 @@ prompt_filthy_git_repo_status() {
local down

dirty="$(git diff --ignore-submodules=all HEAD 2>/dev/null)"
[[ $dirty != "" ]] && rtn+=" %F{red}x%f"
[[ $dirty != "" ]] && rtn+=" %F{242}…%f"

staged="$(git diff --staged HEAD 2>/dev/null)"
[[ $staged != "" ]] && rtn+=" %F{242}*%f"

# check if there is an upstream configured for this branch
# exit if there isn't, as we can't check for remote changes
Expand Down Expand Up @@ -227,9 +261,9 @@ prompt_filthy_git_branch() {
prompt_filthy_connection_info() {
# show username@host if logged in through SSH
if [[ "x$SSH_CONNECTION" != "x" ]]; then
echo '%(!.%F{red}%n%f.%F{242}%n%f)%F{242}@%f%F{green}%m%f '
echo '%(!.%B%F{red}%n%f%b.%F{242}%n%f)%F{242}@%m%f '
else
echo '%(!.%F{red}%n%f%F{242}@%f%F{green}%m%f .)'
echo '%(!.%B%F{red}%n%f%b%F{242}@%m%f .)'
fi
}

Expand All @@ -247,12 +281,9 @@ prompt_filthy_setup() {
add-zsh-hook precmd prompt_filthy_precmd
add-zsh-hook preexec prompt_filthy_preexec

# Define prompts.

RPROMPT='$(prompt_filthy_rprompt)'

# prompt turns red if the previous command didn't exit with 0
PROMPT='$(prompt_filthy_connection_info)%(?.%F{green}.%F{red}$(prompt_filthy_nice_exit_code))❯%f '
RPROMPT='$(prompt_filthy_rprompt)'
}

prompt_filthy_setup "$@"

0 comments on commit f1f1efe

Please sign in to comment.