Parent directory

adben.zsh-theme

4016 bytes
  1#!/usr/bin/env zsh
  2# #
  3# # #README
  4# #
  5# # This theme provides two customizable header functionalities:
  6# # a) displaying a pseudo-random message from a database of quotations
  7# # (https://en.wikipedia.org/wiki/Fortune_%28Unix%29)
  8# # b) displaying randomly command line tips from The command line fu
  9# # (https://www.commandlinefu.com) community: in order to make use of this functionality
 10# # you will need Internet connection.
 11# # This theme provides as well information for the current user's context, like;
 12# # branch and status for the current version control system (git and svn currently
 13# # supported) and time, presented to the user in a non invasive volatile way.
 14# #
 15# # #REQUIREMENTS
 16# # This theme requires wget::
 17# # -Homebrew-osx- brew install wget
 18# # -Debian/Ubuntu- apt-get install wget
 19# # and fortune ::
 20# # -Homebrew-osx- brew install fortune
 21# # -Debian/Ubuntu- apt-get install fortune
 22# #
 23# # optionally:
 24# # -Oh-myzsh vcs plug-ins git and svn.
 25# # -Solarized theme (https://github.com/altercation/solarized/)
 26# # -OS X: iTerm 2 (https://iterm2.com/)
 27# # -font Source code pro (https://github.com/adobe/source-code-pro)
 28# #
 29# # This theme's look and feel is based on the Aaron Toponce's zsh theme, more info:
 30# # https://pthree.org/2008/11/23/727/
 31# # enjoy!
 32
 33########## COLOR ###########
 34for COLOR in CYAN WHITE YELLOW MAGENTA BLACK BLUE RED DEFAULT GREEN GREY; do
 35  typeset -g PR_$COLOR="%b%{$fg[${(L)COLOR}]%}"
 36  typeset -g PR_BRIGHT_$COLOR="%B%{$fg[${(L)COLOR}]%}"
 37done
 38PR_RESET="%{$reset_color%}"
 39
 40RED_START="${PR_GREY}<${PR_RED}<${PR_BRIGHT_RED}<${PR_RESET} "
 41RED_END="${PR_BRIGHT_RED}>${PR_RED}>${PR_GREY}>${PR_RESET} "
 42GREEN_START="${PR_GREY}>${PR_GREEN}>${PR_BRIGHT_GREEN}>${PR_RESET}"
 43GREEN_END="${PR_BRIGHT_GREEN}>${PR_GREEN}>${PR_GREY}>${PR_RESET} "
 44
 45########## VCS ###########
 46VCS_DIRTY_COLOR="${PR_YELLOW}"
 47VCS_CLEAN_COLOR="${PR_GREEN}"
 48VCS_SUFFIX_COLOR="${PR_RED}› ${PR_RESET}"
 49
 50########## SVN ###########
 51ZSH_THEME_SVN_PROMPT_PREFIX="${PR_RED}‹svn:"
 52ZSH_THEME_SVN_PROMPT_SUFFIX="${VCS_SUFFIX_COLOR}"
 53ZSH_THEME_SVN_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘"
 54ZSH_THEME_SVN_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔"
 55
 56########## GIT ###########
 57ZSH_THEME_GIT_PROMPT_PREFIX="${PR_RED}‹git:"
 58ZSH_THEME_GIT_PROMPT_SUFFIX="${VCS_SUFFIX_COLOR}"
 59ZSH_THEME_GIT_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘"
 60ZSH_THEME_GIT_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔"
 61ZSH_THEME_GIT_PROMPT_ADDED="${PR_YELLOW} ✚"
 62ZSH_THEME_GIT_PROMPT_MODIFIED="${PR_YELLOW} ✹"
 63ZSH_THEME_GIT_PROMPT_DELETED="${PR_YELLOW} ✖"
 64ZSH_THEME_GIT_PROMPT_RENAMED="${PR_YELLOW} ➜"
 65ZSH_THEME_GIT_PROMPT_UNMERGED="${PR_YELLOW} ═"
 66ZSH_THEME_GIT_PROMPT_UNTRACKED="${PR_YELLOW} ✭"
 67
 68# Get a fortune quote
 69ps1_fortune() {
 70  if (( ${+commands[fortune]} )); then
 71    fortune
 72  fi
 73}
 74
 75# Obtain a command tip
 76ps1_command_tip() {
 77  {
 78    if (( ${+commands[wget]} )); then
 79      command wget -qO- https://www.commandlinefu.com/commands/random/plaintext
 80    elif (( ${+commands[curl]} )); then
 81      command curl -fsL https://www.commandlinefu.com/commands/random/plaintext
 82    fi
 83  } | sed '1d;/^$/d'
 84}
 85
 86# Show prompt header (fortune / command tip)
 87prompt_header() {
 88  local header=$(
 89    case "${ENABLE_COMMAND_TIP:-}" in
 90    true) ps1_command_tip ;;
 91    *) ps1_fortune ;;
 92    esac
 93  )
 94
 95  # Make sure to quote % so that they're not expanded by the prompt
 96  echo -n "${header:gs/%/%%}"
 97}
 98
 99# Context: user@directory or just directory
100prompt_context() {
101  if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
102    echo -n "${PR_RESET}${PR_RED}%n@%m"
103  fi
104}
105
106########## SETUP ###########
107
108# Required for the prompt
109setopt prompt_subst
110
111# Prompt: header, context (user@host), directory
112PROMPT="${RED_START}${PR_YELLOW}\$(prompt_header)${PR_RESET}
113${RED_START}\$(prompt_context)${PR_BRIGHT_YELLOW}%~${PR_RESET}
114${GREEN_START} "
115# Right prompt: vcs status + time
116RPROMPT="\$(git_prompt_info)\$(svn_prompt_info)${PR_YELLOW}%D{%R.%S %a %b %d %Y} ${GREEN_END}"
117# Matching continuation prompt
118PROMPT2="${GREEN_START} %_ ${GREEN_START} "