Parent directory

emotty.zsh-theme

4234 bytes
  1#!/usr/bin/env zsh
  2# ------------------------------------------------------------------------------
  3#          FILE: emotty.zsh-theme
  4#   DESCRIPTION: A varying emoji based theme
  5#        AUTHOR: Alexis Hildebrandt (afh[at]surryhill.net)
  6#       VERSION: 1.0.0
  7#       DEPENDS: emotty plugin
  8#    RECOMMENDS: Hasklig font
  9#
 10# This theme shows a different emoji for each tty at the main prompt.
 11#
 12# There are pre-defined different emoji sets to choose from, e.g.:
 13# emoji, stellar, floral, zodiac, love (see emotty plugin).
 14#
 15# To choose a different emotty set than the default (emoji)
 16# % export emotty_set=nature
 17#
 18# For the superuser (root) this theme shows a designated indicator
 19# and switches the foreground color to red
 20# (see root_prompt variable, default: skull).
 21# But you are using sudo (8) instead of designated a root shell, right‽
 22#
 23# When logged in via SSH the main prompt also shows the user- and hostname.
 24#
 25# The exit status of the last failed command is displayed in the window title
 26# along with an indicator (see warn_glyph variable, default: collision symbol).
 27# To clear it just run: $NULL, true or :
 28#
 29# The right prompt shows the current working directory (3 levels up) in cyan.
 30#
 31# When in a git repository the main prompt shows the current branch name
 32# with a branch indicator in yellow
 33# (see vcs_branch_glyph variable, default: Hasklig branch glyph).
 34#
 35# If there are modified files the prompt switches to red and shows an unstaged
 36# indicator (see vcs_unstaged_glyph variable, default: circled letter M).
 37#
 38# If there are staged files the prompt switches to green and shows an staged
 39# indicator (see vcs_staged_glyph variable, default: high voltage sign).
 40#
 41# In a git repository the right prompt shows the repository name in bold and
 42# prepends the current working directory subpath within the repository.
 43#
 44# When git currently performs an action such as merge or rebase, the action is
 45# displayed in red instead of the branch name and a special action indicator
 46# is shown (see vcs_action_glyph variable, default: chevron).
 47# ------------------------------------------------------------------------------
 48
 49(( ${+functions[emotty]} )) || {
 50  echo "error: the emotty theme requires the emotty plugin" >&2
 51  return 1
 52}
 53
 54(( ${+emoji} )) || {
 55  echo "error: the emotty theme requires the emoji plugin" >&2
 56  return 1
 57}
 58
 59user_prompt="$(emotty)"
 60root_prompt="$emoji[skull]"
 61warn_prompt="$emoji[collision_symbol]"
 62
 63vcs_unstaged_glyph="%{$emoji[circled_latin_capital_letter_m]$emoji2[emoji_style] %2G%}"
 64vcs_staged_glyph="%{$emoji[high_voltage_sign]%2G%}"
 65vcs_branch_glyph=$'\Ue0a0' # 
 66vcs_action_glyph=$'\U276f' # ❯
 67
 68red="$FG[001]"
 69yellow="$FG[003]"
 70green="$FG[002]"
 71cyan="$FG[014]"
 72
 73prompt_glyph="%{%(#.${root_prompt}.${user_prompt}) %2G%}"
 74
 75# Uncomment the next line if you also like to see the warn_prompt in the prompt on the right.
 76#last_command_failed="%(?.. %F{red}%1{${warn_prompt} %1G%}%?%f)"
 77
 78
 79setopt promptsubst
 80
 81# Workaround for zsh 5.2 release (kudos to @timothybasanov)
 82autoload +X VCS_INFO_nvcsformats
 83functions[VCS_INFO_nvcsformats]=${functions[VCS_INFO_nvcsformats]/local -a msgs/}
 84
 85autoload -U add-zsh-hook
 86autoload -Uz vcs_info
 87
 88zstyle ':vcs_info:*' enable git #hg svn cvs
 89zstyle ':vcs_info:*' get-revision false
 90zstyle ':vcs_info:*' check-for-changes true
 91zstyle ':vcs_info:git:*' unstagedstr "${red}${vcs_unstaged_glyph}"
 92zstyle ':vcs_info:*' stagedstr "${green}${vcs_staged_glyph}"
 93
 94# %(K|F){color} set (back|fore)ground color
 95# %(k|f) reset (back|fore)ground color
 96zstyle ':vcs_info:*' max-exports 3
 97zstyle ':vcs_info:*' nvcsformats "${prompt_glyph}" '%3~' ''
 98zstyle ':vcs_info:*' formats "${yellow}%u%c%b${vcs_branch_glyph}%f" '%S|' "$FX[bold]%r$FX[no-bold]"
 99zstyle ':vcs_info:*' actionformats "${red}%K{white}%a${vcs_action_glyph}%k%f" '%S|' "$FX[bold]%r$FX[no-bold]"
100
101red_if_root="%(!.%F{red}.)"
102sshuser_on_host="${SSH_TTY:+%(!.$red.$yellow)%n@%m$reset_color}"
103
104PROMPT='${sshuser_on_host}${vcs_info_msg_0_}${red_if_root} '
105RPROMPT='${cyan}${vcs_info_msg_1_##.|}${vcs_info_msg_2_}%f${last_command_failed}'
106
107emotty_title() {
108  title "${${?/[^0]*/$warn_prompt $?}/0/${prompt_glyph}}"
109}
110add-zsh-hook precmd emotty_title
111add-zsh-hook precmd vcs_info
112
113# vim:ft=zsh ts=2 sw=2 sts=2