Skip to content

Commit

Permalink
Support changing color of the Git action part of the prompt (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashb authored and sindresorhus committed Oct 14, 2019
1 parent 8c0ba7d commit 72f59dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
17 changes: 12 additions & 5 deletions pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ prompt_pure_preprompt_render() {
# Add Git branch and dirty status info.
typeset -gA prompt_pure_vcs_info
if [[ -n $prompt_pure_vcs_info[branch] ]]; then
preprompt_parts+=("%F{$git_color}"'${prompt_pure_vcs_info[branch]}${prompt_pure_git_dirty}%f')
local branch="%F{$git_color}"'${prompt_pure_vcs_info[branch]}'
if [[ -n $prompt_pure_vcs_info[action] ]]; then
branch+="|%F{$prompt_pure_colors[git:action]}"'$prompt_pure_vcs_info[action]'"%F{$git_color}"
fi
preprompt_parts+=("$branch"'${prompt_pure_git_dirty}%f')
fi
# Git pull/push arrows.
if [[ -n $prompt_pure_git_arrows ]]; then
Expand Down Expand Up @@ -248,18 +252,19 @@ prompt_pure_async_vcs_info() {
# to be used or configured as the user pleases.
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' use-simple true
# Only export two message variables from `vcs_info`.
zstyle ':vcs_info:*' max-exports 2
# Export branch (%b) and Git toplevel (%R).
# Only export three message variables from `vcs_info`.
zstyle ':vcs_info:*' max-exports 3
# Export branch (%b), Git toplevel (%R), and action (rebase/cherry-pick) (%a).
zstyle ':vcs_info:git*' formats '%b' '%R'
zstyle ':vcs_info:git*' actionformats '%b|%a' '%R'
zstyle ':vcs_info:git*' actionformats '%b' '%R' '%a'

vcs_info

local -A info
info[pwd]=$PWD
info[top]=$vcs_info_msg_1_
info[branch]=$vcs_info_msg_0_
info[action]=$vcs_info_msg_2_

print -r - ${(@kvq)info}
}
Expand Down Expand Up @@ -446,6 +451,7 @@ prompt_pure_async_callback() {
# Always update branch and top-level.
prompt_pure_vcs_info[branch]=$info[branch]
prompt_pure_vcs_info[top]=$info[top]
prompt_pure_vcs_info[action]=$info[action]

do_render=1
;;
Expand Down Expand Up @@ -672,6 +678,7 @@ prompt_pure_setup() {
git:arrow cyan
git:branch 242
git:branch:cached red
git:action 242
host 242
path blue
prompt:error red
Expand Down
20 changes: 11 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Colors can be changed by using [`zstyle`](http://zsh.sourceforge.net/Doc/Release
- `git:arrow` (cyan) - For `PURE_GIT_UP_ARROW` and `PURE_GIT_DOWN_ARROW`.
- `git:branch` (242) - The name of the current branch when in a Git repository.
- `git:branch:cached` (red) - The name of the current branch when the data isn't fresh.
- `git:action` (242) - The current action in progress (cherry-pick, rebase, etc.) when in a Git repository.
- `host` (242) - The hostname when on a remote machine.
- `path` (blue) - The current path, for example, `PWD`.
- `prompt:error` (red) - The `PURE_PROMPT_SYMBOL` when the previous command has *failed*.
Expand All @@ -97,15 +98,16 @@ The following diagram shows where each color is applied on the prompt:
```
┌───────────────────────────────────────────── path
│ ┌────────────────────────────────── git:branch
│ │ ┌────────────────────────── git:arrow
│ │ │ ┌───────────────── host
│ │ │ │
~/dev/pure master* ⇡ zaphod@heartofgold 42s
venv ❯ │ │
│ │ │ └───── execution_time
│ │ └──────────────────────── user
│ └──────────────────────────────────────── prompt
└───────────────────────────────────────────── virtualenv
│ │ ┌─────────────────────────── git:action
│ │ │ ┌───────────────── git:arrow
│ │ │ │ ┌──────── host
│ │ │ │ │
~/dev/pure master|rebase-i* ⇡ zaphod@heartofgold 42s
venv ❯ │ │
│ │ │ └───── execution_time
│ │ └──────────────────────── user
│ └───────────────────────────────────────────────── prompt
└────────────────────────────────────────────────────── virtualenv
```

### RGB colors
Expand Down

0 comments on commit 72f59dd

Please sign in to comment.