adben.zsh-theme 4.45 KB
Newer Older
1
#!/usr/bin/env zsh
2
3
4
# #
# # #README
# #
5
# # This theme provides two customizable header functionalities:
6
7
# # a) displaying a pseudo-random message from a database of quotations
# # (https://en.wikipedia.org/wiki/Fortune_%28Unix%29)
8
# # b) displaying randomly command line tips from The command line fu
Janosch Schwalm's avatar
Janosch Schwalm committed
9
# # (https://www.commandlinefu.com) community: in order to make use of this functionality
10
# # you will need Internet connection.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# # This theme provides as well information for the current user's context, like;
# # branch and status for the current version control system (git and svn currently
# # supported) and time, presented to the user in a non invasive volatile way.
# #
# # #REQUIREMENTS
# # This theme requires wget::
# # -Homebrew-osx- brew install wget
# # -Debian/Ubuntu- apt-get install wget
# # and fortune ::
# # -Homebrew-osx- brew install fortune
# # -Debian/Ubuntu- apt-get install fortune
# #
# # optionally:
# # -Oh-myzsh vcs plug-ins git and svn.
# # -Solarized theme (https://github.com/altercation/solarized/)
Janosch Schwalm's avatar
Janosch Schwalm committed
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:
Janosch Schwalm's avatar
Janosch Schwalm committed
30
# # https://pthree.org/2008/11/23/727/
31
# # enjoy!
32

33
34
########## COLOR ###########
for COLOR in CYAN WHITE YELLOW MAGENTA BLACK BLUE RED DEFAULT GREEN GREY; do
35
36
  eval PR_$COLOR='%{$fg[${(L)COLOR}]%}'
  eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
37
done
38

39
40
41
42
43
44
45
46
PR_RESET="%{$reset_color%}"
RED_START="${PR_RESET}${PR_GREY}<${PR_RESET}${PR_RED}<${PR_BRIGHT_RED}<${PR_RESET} "
RED_END="${PR_RESET}${PR_BRIGHT_RED}>${PR_RESET}${PR_RED}>${PR_GREY}>${PR_RESET} "
GREEN_END="${PR_RESET}${PR_BRIGHT_GREEN}>${PR_RESET}${PR_GREEN}>${PR_GREY}>${PR_RESET} "
GREEN_BASE_START="${PR_RESET}${PR_GREY}>${PR_RESET}${PR_GREEN}>${PR_BRIGHT_GREEN}>${PR_RESET}"
GREEN_START_P1="${PR_RESET}${GREEN_BASE_START}${PR_RESET} "
DIVISION="${PR_RESET}${PR_RED} < ${PR_RESET}"
VCS_DIRTY_COLOR="${PR_RESET}${PR_YELLOW}"
47
VCS_CLEAN_COLOR="${PR_RESET}${PR_GREEN}"
48
VCS_SUFIX_COLOR="${PR_RESET}${PR_RED}${PR_RESET}"
49
50

########## SVN ###########
51
52
53
54
ZSH_THEME_SVN_PROMPT_PREFIX="${PR_RESET}${PR_RED}‹svn:"
ZSH_THEME_SVN_PROMPT_SUFFIX=""
ZSH_THEME_SVN_PROMPT_DIRTY="${VCS_DIRTY_COLOR}${VCS_SUFIX_COLOR}"
ZSH_THEME_SVN_PROMPT_CLEAN="${VCS_CLEAN_COLOR}${VCS_SUFIX_COLOR}"
55
56

########## GIT ###########
57
58
59
60
61
62
63
64
65
66
ZSH_THEME_GIT_PROMPT_PREFIX="${PR_RESET}${PR_RED}‹git:"
ZSH_THEME_GIT_PROMPT_SUFFIX=""
ZSH_THEME_GIT_PROMPT_DIRTY="${VCS_DIRTY_COLOR}${VCS_SUFIX_COLOR}"
ZSH_THEME_GIT_PROMPT_CLEAN="${VCS_CLEAN_COLOR}${VCS_SUFIX_COLOR}"
ZSH_THEME_GIT_PROMPT_ADDED="${PR_RESET}${PR_YELLOW}${PR_RESET}"
ZSH_THEME_GIT_PROMPT_MODIFIED="${PR_RESET}${PR_YELLOW}${PR_RESET}"
ZSH_THEME_GIT_PROMPT_DELETED="${PR_RESET}${PR_YELLOW}${PR_RESET}"
ZSH_THEME_GIT_PROMPT_RENAMED="${PR_RESET}${PR_YELLOW}${PR_RESET}"
ZSH_THEME_GIT_PROMPT_UNMERGED="${PR_RESET}${PR_YELLOW}${PR_RESET}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="${PR_RESET}${PR_YELLOW}${PR_RESET}"
67
68
69
70
71
72
73
74
75
76
77
78
79

# Get a fortune quote
ps1_fortune() {
  (( ${+commands[fortune]} )) && fortune
}

# Obtain a command tip
ps1_command_tip() {
  {
    if (( ${+commands[wget]} )); then
      command wget -qO- https://www.commandlinefu.com/commands/random/plaintext
    elif (( ${+commands[curl]} )); then
      command curl -fsL https://www.commandlinefu.com/commands/random/plaintext
80
    fi
81
  } | sed 1d | sed '/^$/d'
82
83
}

84
85
86
87
function precmd_adben {
  prompt_header() {
    if [[ "$ENABLE_COMMAND_TIP" = true ]]; then
      ps1_command_tip
88
    else
89
      ps1_fortune
90
    fi
91
92
93
94
95
96
97
98
  }

  PROMPT_HEAD="${RED_START}${PR_YELLOW}$(prompt_header)${PR_RESET}"

  # set a simple variable to show when in screen
  if [[ -n "${WINDOW}" ]]; then
    SCREEN=""
  fi
99
100
}

101
102
103
104
105
106
107
108
# Context: user@directory or just directory
prompt_context() {
  if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    echo -n "${PR_RESET}${PR_RED}$USERNAME@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
  else
    echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
  fi
}
109

110
111
112
113
114
115
116
117
########## SETUP ###########

# Required for the prompt
setopt prompt_subst
autoload zsh/terminfo

# Prompt
PROMPT='${PROMPT_HEAD}
118
119
${RED_START}$(prompt_context)
${GREEN_START_P1}'
120
121
122
RPROMPT='${PR_RESET}$(git_prompt_info)$(svn_prompt_info)${PR_YELLOW}%D{%R.%S %a %b %d %Y} ${GREEN_END}${PR_RESET}'
# Matching continuation prompt
PROMPT2='${GREEN_BASE_START}${PR_RESET} %_ ${GREEN_BASE_START}${PR_RESET} '
123

124
125
126
# Prompt head
autoload -Uz add-zsh-hook
add-zsh-hook precmd precmd_adben