daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest May 16th, 2018 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # The prompt
  2. PROMPT='$(_user_host)$(_python_venv)%{$fg[cyan]%}%c $(git_prompt_info)%{$reset_color%}$(_git_time_since_commit)$(git_prompt_status)${_return_status}➜ '
  3.  
  4. # Prompt with SHA
  5. # PROMPT='$(_user_host)$(_python_venv)%{$fg[cyan]%}%c $(git_prompt_info)%{$reset_color%}$(git_prompt_short_sha)%{$fg[magenta]%}$(_git_time_since_commit)$(git_prompt_status)${_return_status}➜ '
  6.  
  7. local _return_status="%{$fg[red]%}%(?..⍉ )%{$reset_color%}"
  8.  
  9. function _user_host() {
  10.   if [[ -n $SSH_CONNECTION ]]; then
  11.     me="%n@%m"
  12.   elif [[ $LOGNAME != $USER ]]; then
  13.     me="%n"
  14.   fi
  15.   if [[ -n $me ]]; then
  16.     echo "%{$fg[cyan]%}$me%{$reset_color%}:"
  17.   fi
  18. }
  19.  
  20. # Determine if there is an active Python virtual environment
  21. function _python_venv() {
  22.   if [[ $VIRTUAL_ENV != "" ]]; then
  23.     echo "%{$fg[blue]%}(${VIRTUAL_ENV##*/})%{$reset_color%} "
  24.   fi
  25. }
  26.  
  27. # Format for git_prompt_long_sha() and git_prompt_short_sha()
  28. ZSH_THEME_GIT_PROMPT_SHA_BEFORE="%{%F{yellow}%}"
  29. ZSH_THEME_GIT_PROMPT_SHA_AFTER="%{$reset_color%} "
  30.  
  31. ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
  32. ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
  33. ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}✗%{$reset_color%} "
  34. ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[white]%}◒ "
  35. ZSH_THEME_GIT_PROMPT_CLEAN=" "
  36. ZSH_THEME_GIT_PROMPT_ADDED="%{$fg[cyan]%}✓ "
  37. ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg[yellow]%}△ "
  38. ZSH_THEME_GIT_PROMPT_DELETED="%{$fg[red]%}✖ "
  39. ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg[blue]%}➜ "
  40. ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg[cyan]%}§ "
  41. ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg[blue]%}▲ "
  42.  
  43. ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[white]%}"
  44. ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
  45. ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
  46. ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[white]%}"
  47.  
  48. #
  49. # Determine the time since last commit. If branch is clean,
  50. # use a neutral color, otherwise colors will vary according to time.
  51. function _git_time_since_commit() {
  52. # Only proceed if there is actually a commit.
  53.   if git log -1 > /dev/null 2>&1; then
  54.     # Get the last commit.
  55.     last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null)
  56.     now=$(date +%s)
  57.     seconds_since_last_commit=$((now-last_commit))
  58.  
  59.     # Totals
  60.     minutes=$((seconds_since_last_commit / 60))
  61.     hours=$((seconds_since_last_commit/3600))
  62.  
  63.     # Sub-hours and sub-minutes
  64.     days=$((seconds_since_last_commit / 86400))
  65.     sub_hours=$((hours % 24))
  66.     sub_minutes=$((minutes % 60))
  67.  
  68.     if [ $hours -gt 24 ]; then
  69.       commit_age="${days}d "
  70.     elif [ $minutes -gt 60 ]; then
  71.       commit_age="${sub_hours}h${sub_minutes}m "
  72.     else
  73.       commit_age="${minutes}m "
  74.     fi
  75.     if [[ -n $(git status -s 2> /dev/null) ]]; then
  76.         if [ "$hours" -gt 4 ]; then
  77.             COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
  78.         elif [ "$minutes" -gt 30 ]; then
  79.             COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
  80.         else
  81.             COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
  82.         fi
  83.     else
  84.         COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
  85.     fi
  86.  
  87.  
  88.     echo "$COLOR$commit_age%{$reset_color%}"
  89.   fi
  90. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top