Created
October 15, 2018 15:28
-
-
Save badboy/081d680aaa4607bbcbb4672081113c5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: ft=sh | |
# via: https://github.com/mitsuhiko/dotfiles/blob/master/zsh/custom/themes/mitsuhiko.zsh-theme | |
setopt prompt_subst | |
export LSCOLORS=ExGxFxDxCxHxHxCbCeEbEb | |
ZSH_THEME_GIT_PROMPT_PREFIX=" on %{$fg[blue]%}git%{$reset_color%}:" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}+" | |
ZSH_THEME_GIT_PROMPT_BRANCH="" | |
ZSH_THEME_GIT_PROMPT_SEPARATOR="" | |
ZSH_THEME_GIT_PROMPT_CLEAN="" | |
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[green]?%G%}" | |
ZSH_THEME_GIT_PROMPT_CHANGED="%{$fg[cyan]%}%{+%G%}" | |
ZSH_THEME_HG_PROMPT_PREFIX=" on %{$fg[blue]%}hg%{$reset_color%}:" | |
ZSH_THEME_HG_PROMPT_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_HG_PROMPT_DIRTY="%{$fg[green]%}+" | |
ZSH_THEME_VIRTUALENV_PREFIX=" workon %{$fg[red]%}" | |
ZSH_THEME_VIRTUALENV_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_MULTIRUST_PREFIX=" rust %{$fg[magenta]%}" | |
ZSH_THEME_MULTIRUST_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_PLANEINFO_TEMPLATE=" aboard %{$fg[cyan]%}:orig_airport%{$reset_color%}-%{$fg[yellow]%}:dst_airport%{$reset_color%} on %{$fg[magenta]%}:flight_number%{$reset_color%} eta %{$fg[green]%}T-:eta%{$reset_color%}%{$fg[red]%}:not_online_marker%{$reset_color%}" | |
ZSH_THEME_TRAININFO_TEMPLATE=" aboard %{$fg[magenta]%}:train_number%{$reset_color%} to %{$fg[cyan]%}:dst_station%{$reset_color%} eta %{$fg[green]%}T-:eta%{$reset_color%}%{$fg[red]%}:not_online_marker%{$reset_color%}" | |
# If iTerm is detected these themes are used for regular windows | |
# and ssh respectively | |
JANERIK_ITERM_NORMAL_PROFILE='Fancy' | |
JANERIK_ITERM_SSH_PROFILE='FancySSH' | |
# This is the basic prompt that is always printed. It will be | |
# enclosed to make it newline. | |
_JANERIK_PROMPT='[%{$fg[green]%}%~%{$reset_color%}]' | |
# This is the base prompt that is rendered sync. It should be | |
# fast to render as a result. The extra whitespace before the | |
# newline is necessary to avoid some rendering bugs. | |
PROMPT=$'\n'$_JANERIK_PROMPT$'\n❯ ' | |
RPROMPT='' | |
# The pid of the async prompt process and the communication file | |
_JANERIK_ASYNC_PROMPT=0 | |
_JANERIK_ASYNC_PROMPT_FN="/tmp/.zsh_tmp_prompt_$$" | |
# This here implements the async handling of the prompt. It | |
# runs the expensive git parts in a subprocess and passes the | |
# information back via tempfile. | |
function _janerik_precmd() { | |
_janerik_rv=$? | |
function async_prompt() { | |
# Don't report any long running program | |
unset REPORTTIME | |
echo -n $'\n'$_JANERIK_PROMPT$' '$(__ps1_git_state)$(__ps1_hg_state)$(__ruby_prompt)$(__rust_prompt) > $_JANERIK_ASYNC_PROMPT_FN | |
if [[ x$_janerik_rv != x0 ]]; then | |
echo -n " exited %{$fg[red]%}$_janerik_rv%{$reset_color%}" >> $_JANERIK_ASYNC_PROMPT_FN | |
fi | |
echo -n $' \n❯ ' >> $_JANERIK_ASYNC_PROMPT_FN | |
# signal parent | |
kill -s USR1 $$ | |
} | |
# If we still have a prompt async process we kill it to make sure | |
# we do not backlog with useless prompt things. This also makes | |
# sure that we do not have prompts interleave in the tempfile. | |
if [[ "${_JANERIK_ASYNC_PROMPT}" != 0 ]]; then | |
kill -s HUP $_JANERIK_ASYNC_PROMPT >/dev/null 2>&1 || : | |
fi | |
# start background computation | |
async_prompt &! | |
_JANERIK_ASYNC_PROMPT=$! | |
} | |
# This is the trap for the signal that updates our prompt and | |
# redraws it. We intentionally do not delete the tempfile here | |
# so that we can reuse the last prompt for successive commands | |
function _janerik_trapusr1() { | |
PROMPT="$(cat $_JANERIK_ASYNC_PROMPT_FN)" | |
_JANERIK_ASYNC_PROMPT=0 | |
zle && zle reset-prompt | |
} | |
# Make sure we clean up our tempfile on exit | |
function _janerik_zshexit() { | |
rm -f $_JANERIK_ASYNC_PROMPT_FN | |
} | |
# Hook our precmd and zshexit functions and USR1 trap | |
precmd_functions+=(_janerik_precmd) | |
zshexit_functions+=(_janerik_zshexit) | |
trap '_janerik_trapusr1' USR1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment