Skip to content

Commit 72f59dd

Browse files
ashbsindresorhus
authored andcommitted
Support changing color of the Git action part of the prompt (#486)
1 parent 8c0ba7d commit 72f59dd

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

pure.zsh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ prompt_pure_preprompt_render() {
134134
# Add Git branch and dirty status info.
135135
typeset -gA prompt_pure_vcs_info
136136
if [[ -n $prompt_pure_vcs_info[branch] ]]; then
137-
preprompt_parts+=("%F{$git_color}"'${prompt_pure_vcs_info[branch]}${prompt_pure_git_dirty}%f')
137+
local branch="%F{$git_color}"'${prompt_pure_vcs_info[branch]}'
138+
if [[ -n $prompt_pure_vcs_info[action] ]]; then
139+
branch+="|%F{$prompt_pure_colors[git:action]}"'$prompt_pure_vcs_info[action]'"%F{$git_color}"
140+
fi
141+
preprompt_parts+=("$branch"'${prompt_pure_git_dirty}%f')
138142
fi
139143
# Git pull/push arrows.
140144
if [[ -n $prompt_pure_git_arrows ]]; then
@@ -248,18 +252,19 @@ prompt_pure_async_vcs_info() {
248252
# to be used or configured as the user pleases.
249253
zstyle ':vcs_info:*' enable git
250254
zstyle ':vcs_info:*' use-simple true
251-
# Only export two message variables from `vcs_info`.
252-
zstyle ':vcs_info:*' max-exports 2
253-
# Export branch (%b) and Git toplevel (%R).
255+
# Only export three message variables from `vcs_info`.
256+
zstyle ':vcs_info:*' max-exports 3
257+
# Export branch (%b), Git toplevel (%R), and action (rebase/cherry-pick) (%a).
254258
zstyle ':vcs_info:git*' formats '%b' '%R'
255-
zstyle ':vcs_info:git*' actionformats '%b|%a' '%R'
259+
zstyle ':vcs_info:git*' actionformats '%b' '%R' '%a'
256260

257261
vcs_info
258262

259263
local -A info
260264
info[pwd]=$PWD
261265
info[top]=$vcs_info_msg_1_
262266
info[branch]=$vcs_info_msg_0_
267+
info[action]=$vcs_info_msg_2_
263268

264269
print -r - ${(@kvq)info}
265270
}
@@ -446,6 +451,7 @@ prompt_pure_async_callback() {
446451
# Always update branch and top-level.
447452
prompt_pure_vcs_info[branch]=$info[branch]
448453
prompt_pure_vcs_info[top]=$info[top]
454+
prompt_pure_vcs_info[action]=$info[action]
449455

450456
do_render=1
451457
;;
@@ -672,6 +678,7 @@ prompt_pure_setup() {
672678
git:arrow cyan
673679
git:branch 242
674680
git:branch:cached red
681+
git:action 242
675682
host 242
676683
path blue
677684
prompt:error red

readme.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Colors can be changed by using [`zstyle`](http://zsh.sourceforge.net/Doc/Release
8484
- `git:arrow` (cyan) - For `PURE_GIT_UP_ARROW` and `PURE_GIT_DOWN_ARROW`.
8585
- `git:branch` (242) - The name of the current branch when in a Git repository.
8686
- `git:branch:cached` (red) - The name of the current branch when the data isn't fresh.
87+
- `git:action` (242) - The current action in progress (cherry-pick, rebase, etc.) when in a Git repository.
8788
- `host` (242) - The hostname when on a remote machine.
8889
- `path` (blue) - The current path, for example, `PWD`.
8990
- `prompt:error` (red) - The `PURE_PROMPT_SYMBOL` when the previous command has *failed*.
@@ -97,15 +98,16 @@ The following diagram shows where each color is applied on the prompt:
9798
```
9899
┌───────────────────────────────────────────── path
99100
│ ┌────────────────────────────────── git:branch
100-
│ │ ┌────────────────────────── git:arrow
101-
│ │ │ ┌───────────────── host
102-
│ │ │ │
103-
~/dev/pure master* ⇡ zaphod@heartofgold 42s
104-
venv ❯ │ │
105-
│ │ │ └───── execution_time
106-
│ │ └──────────────────────── user
107-
│ └──────────────────────────────────────── prompt
108-
└───────────────────────────────────────────── virtualenv
101+
│ │ ┌─────────────────────────── git:action
102+
│ │ │ ┌───────────────── git:arrow
103+
│ │ │ │ ┌──────── host
104+
│ │ │ │ │
105+
~/dev/pure master|rebase-i* ⇡ zaphod@heartofgold 42s
106+
venv ❯ │ │
107+
│ │ │ └───── execution_time
108+
│ │ └──────────────────────── user
109+
│ └───────────────────────────────────────────────── prompt
110+
└────────────────────────────────────────────────────── virtualenv
109111
```
110112

111113
### RGB colors

0 commit comments

Comments
 (0)