2011-08-02 15:42:23 +08:00
|
|
|
|
#!/usr/bin/env zsh
|
2013-01-31 01:58:58 +08:00
|
|
|
|
# #
|
|
|
|
|
# # #README
|
|
|
|
|
# #
|
2014-03-09 01:51:16 +08:00
|
|
|
|
# # This theme provides two customizable header functionalities:
|
2013-01-31 01:58:58 +08:00
|
|
|
|
# # a) displaying a pseudo-random message from a database of quotations
|
|
|
|
|
# # (https://en.wikipedia.org/wiki/Fortune_%28Unix%29)
|
2014-03-09 01:51:16 +08:00
|
|
|
|
# # b) displaying randomly command line tips from The command line fu
|
2018-08-08 02:42:02 +08:00
|
|
|
|
# # (https://www.commandlinefu.com) community: in order to make use of this functionality
|
2014-03-09 01:51:16 +08:00
|
|
|
|
# # you will need Internet connection.
|
2013-01-31 01:58:58 +08:00
|
|
|
|
# # 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/)
|
2018-08-08 02:42:02 +08:00
|
|
|
|
# # -OS X: iTerm 2 (https://iterm2.com/)
|
2013-01-31 01:58:58 +08:00
|
|
|
|
# # -font Source code pro (https://github.com/adobe/source-code-pro)
|
2014-03-09 01:51:16 +08:00
|
|
|
|
# #
|
|
|
|
|
# # This theme's look and feel is based on the Aaron Toponce's zsh theme, more info:
|
2018-08-08 02:42:02 +08:00
|
|
|
|
# # https://pthree.org/2008/11/23/727/
|
2013-01-31 01:58:58 +08:00
|
|
|
|
# # enjoy!
|
2021-03-28 21:28:01 +08:00
|
|
|
|
|
2013-01-31 01:58:58 +08:00
|
|
|
|
########## COLOR ###########
|
|
|
|
|
for COLOR in CYAN WHITE YELLOW MAGENTA BLACK BLUE RED DEFAULT GREEN GREY; do
|
2021-12-16 17:15:55 +08:00
|
|
|
|
typeset -g PR_$COLOR="%b%{$fg[${(L)COLOR}]%}"
|
|
|
|
|
typeset -g PR_BRIGHT_$COLOR="%B%{$fg[${(L)COLOR}]%}"
|
2013-01-31 01:58:58 +08:00
|
|
|
|
done
|
|
|
|
|
PR_RESET="%{$reset_color%}"
|
2021-12-01 00:37:29 +08:00
|
|
|
|
|
|
|
|
|
RED_START="${PR_GREY}<${PR_RED}<${PR_BRIGHT_RED}<${PR_RESET} "
|
|
|
|
|
RED_END="${PR_BRIGHT_RED}>${PR_RED}>${PR_GREY}>${PR_RESET} "
|
|
|
|
|
GREEN_START="${PR_GREY}>${PR_GREEN}>${PR_BRIGHT_GREEN}>${PR_RESET}"
|
|
|
|
|
GREEN_END="${PR_BRIGHT_GREEN}>${PR_GREEN}>${PR_GREY}>${PR_RESET} "
|
|
|
|
|
|
|
|
|
|
########## VCS ###########
|
|
|
|
|
VCS_DIRTY_COLOR="${PR_YELLOW}"
|
|
|
|
|
VCS_CLEAN_COLOR="${PR_GREEN}"
|
|
|
|
|
VCS_SUFFIX_COLOR="${PR_RED}› ${PR_RESET}"
|
2021-03-28 21:28:01 +08:00
|
|
|
|
|
|
|
|
|
########## SVN ###########
|
2021-12-01 00:37:29 +08:00
|
|
|
|
ZSH_THEME_SVN_PROMPT_PREFIX="${PR_RED}‹svn:"
|
|
|
|
|
ZSH_THEME_SVN_PROMPT_SUFFIX="${VCS_SUFFIX_COLOR}"
|
|
|
|
|
ZSH_THEME_SVN_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘"
|
|
|
|
|
ZSH_THEME_SVN_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔"
|
2021-03-28 21:28:01 +08:00
|
|
|
|
|
|
|
|
|
########## GIT ###########
|
2021-12-01 00:37:29 +08:00
|
|
|
|
ZSH_THEME_GIT_PROMPT_PREFIX="${PR_RED}‹git:"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_SUFFIX="${VCS_SUFFIX_COLOR}"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_DIRTY="${VCS_DIRTY_COLOR} ✘"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_CLEAN="${VCS_CLEAN_COLOR} ✔"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_ADDED="${PR_YELLOW} ✚"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_MODIFIED="${PR_YELLOW} ✹"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_DELETED="${PR_YELLOW} ✖"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_RENAMED="${PR_YELLOW} ➜"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNMERGED="${PR_YELLOW} ═"
|
|
|
|
|
ZSH_THEME_GIT_PROMPT_UNTRACKED="${PR_YELLOW} ✭"
|
2021-03-28 21:28:01 +08:00
|
|
|
|
|
|
|
|
|
# Get a fortune quote
|
|
|
|
|
ps1_fortune() {
|
2021-12-01 00:37:29 +08:00
|
|
|
|
if (( ${+commands[fortune]} )); then
|
|
|
|
|
fortune
|
|
|
|
|
fi
|
2021-03-28 21:28:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 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
|
2024-03-26 16:55:16 +08:00
|
|
|
|
fi
|
2021-12-01 00:37:29 +08:00
|
|
|
|
} | sed '1d;/^$/d'
|
2013-01-31 01:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-01 00:37:29 +08:00
|
|
|
|
# Show prompt header (fortune / command tip)
|
|
|
|
|
prompt_header() {
|
|
|
|
|
local header=$(
|
|
|
|
|
case "${ENABLE_COMMAND_TIP:-}" in
|
|
|
|
|
true) ps1_command_tip ;;
|
|
|
|
|
*) ps1_fortune ;;
|
|
|
|
|
esac
|
|
|
|
|
)
|
2021-03-28 21:28:01 +08:00
|
|
|
|
|
2021-12-01 00:37:29 +08:00
|
|
|
|
# Make sure to quote % so that they're not expanded by the prompt
|
|
|
|
|
echo -n "${header:gs/%/%%}"
|
2013-01-31 01:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-28 21:28:01 +08:00
|
|
|
|
# Context: user@directory or just directory
|
|
|
|
|
prompt_context() {
|
|
|
|
|
if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
2021-12-01 00:37:29 +08:00
|
|
|
|
echo -n "${PR_RESET}${PR_RED}%n@%m"
|
2021-03-28 21:28:01 +08:00
|
|
|
|
fi
|
|
|
|
|
}
|
2015-02-10 03:43:48 +08:00
|
|
|
|
|
2021-03-28 21:28:01 +08:00
|
|
|
|
########## SETUP ###########
|
|
|
|
|
|
|
|
|
|
# Required for the prompt
|
|
|
|
|
setopt prompt_subst
|
|
|
|
|
|
2021-12-01 00:37:29 +08:00
|
|
|
|
# Prompt: header, context (user@host), directory
|
|
|
|
|
PROMPT="${RED_START}${PR_YELLOW}\$(prompt_header)${PR_RESET}
|
|
|
|
|
${RED_START}\$(prompt_context)${PR_BRIGHT_YELLOW}%~${PR_RESET}
|
|
|
|
|
${GREEN_START} "
|
|
|
|
|
# Right prompt: vcs status + time
|
|
|
|
|
RPROMPT="\$(git_prompt_info)\$(svn_prompt_info)${PR_YELLOW}%D{%R.%S %a %b %d %Y} ${GREEN_END}"
|
2021-03-28 21:28:01 +08:00
|
|
|
|
# Matching continuation prompt
|
2021-12-01 00:37:29 +08:00
|
|
|
|
PROMPT2="${GREEN_START} %_ ${GREEN_START} "
|