Skip to content

Commit bfb5edf

Browse files
committed
feat(usage): rewrite
1 parent 573b386 commit bfb5edf

File tree

1 file changed

+65
-38
lines changed

1 file changed

+65
-38
lines changed

docs/usage.md

+65-38
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
# Usage
22

3-
Git Prompt Kit takes the work out of add high-performance Git information to your custom prompt.
3+
Git Prompt Kit takes the work out of adding high-performance Git information to your custom zsh theme.
44

5-
Say you want your prompt to show the current working directory; the Git branch if you're in a Git repo and on a branch, the Git commit if you're in a repo and not on a branch, colored if the working tree is dirty; and `%` when you aren't root but a `#` when you are, colored depending on whether the previous command succeeded or failed.
5+
Say you want your prompt to show the current working directory; the Git branch if you're in a Git repo and on a branch, the Git commit if you're in a repo and not on a branch, colored if the working tree is dirty; and `%` when you aren't root but a `#` when you are, colored depending on whether the previous command succeeded or failed. The vanilla way is add a `preexec` hook, and write some logic to get the branch with a commit SHA fallback. That might look like the example below.
66

77
:::tip
8-
In the examples below,
9-
10-
- the construct `${x:+y}` is "print `$y` if `$x` is not null". In the context of prompt building, this is useful for conditionally adding spaces: `${x:+$x }` is "print `$x ` if `$x` is not null".
11-
- colors are always customized. That's never required. In the example which doesn't use Git Prompt Kit, you could leave out the coloring and have a monochrome prompt. In the examples which use Git Prompt Kit, you could leave out the color definitions and you'd get the [default Git Prompt Kit colors](/options.html#color-options).
12-
:::
13-
14-
You could add a `preexec` hook, and write some logic to get the branch with a commit SHA fallback.
8+
The following examples use the construct `${x:+y}`. That's "`$y` if `$x` is not null". In the context of prompt building, this is useful for conditionally adding spaces: `${x:+$x }` is "`$x ` if `$x` is not null".
9+
:::
1510

1611
```shell
1712
# ~/.zshrc
13+
1814
set_prompt_vars() {
1915
# define prompt_git_head
2016
# define prompt_git_dirty only if the working tree is dirty
2117
}
18+
2219
autoload -Uz add-zsh-hook
23-
add-zsh-hook precmd set_git_head
24-
prompt_directory_color=#
25-
prompt_git_head_color=#
26-
prompt_failure_color=#
27-
prompt_success_color=#
20+
add-zsh-hook precmd set_prompt_vars
21+
22+
prompt_directory_color=your_value_here
23+
prompt_git_head_color=your_value_here
24+
prompt_failure_color=your_value_here
25+
prompt_success_color=your_value_here
26+
27+
# directory
2828
PROMPT='%F{$prompt_directory_color}%1d%f '
29+
30+
# Git HEAD
2931
PROMPT+='${prompt_git_head:+ ${prompt_git_dirty:+%F{$prompt_git_head_color}}$prompt_git_head%f }'
32+
33+
# prompt char
3034
PROMPT+='%F{%(?.$prompt_success_color.$prompt_failure_color)}%(!.#.$)%f '
3135
```
3236

@@ -36,55 +40,78 @@ Or you could use Git Prompt Kit's Git HEAD component. It's colored when the work
3640

3741
```shell
3842
# ~/.zshrc
39-
# optional
40-
GIT_PROMPT_KIT_COLOR_HEAD=#
41-
# load Git Prompt Kit
42-
prompt_directory_color=#
43-
prompt_failure_color=#
44-
prompt_success_color=#
43+
44+
# load Git Prompt Kit and then
45+
46+
prompt_directory_color=your_value_here
47+
prompt_failure_color=your_value_here
48+
prompt_success_color=your_value_here
49+
50+
# directory
4551
PROMPT='%F{$prompt_directory_color}%1d%f '
52+
4653
PROMPT+='${GIT_PROMPT_KIT_HEAD:+$GIT_PROMPT_KIT_HEAD }'
54+
55+
# prompt char
4756
PROMPT+='%F{%(?.$prompt_success_color.$prompt_failure_color)}%(!.#.$)%f '
4857
```
4958

5059
Using Git Prompt Kit's current working directory component will add some fanciness. You'll know immediately whether or not you're in a Git repo, because the component underlines Git root directories. And if you're in subdirectory of a repo, you'll know which repo you're in, because the component prepends the repo root (underlined, of course) to PWD.
5160

5261
```shell
5362
# ~/.zshrc
54-
# optional
55-
GIT_PROMPT_KIT_COLOR_CWD=#
56-
# optional
57-
GIT_PROMPT_KIT_COLOR_HEAD=#
58-
# load Git Prompt Kit
59-
prompt_failure_color=#
60-
prompt_success_color=#
63+
64+
# load Git Prompt Kit and then
65+
66+
prompt_failure_color=your_value_here
67+
prompt_success_color=your_value_here
68+
6169
PROMPT='$GIT_PROMPT_KIT_CWD '
6270
PROMPT+='${GIT_PROMPT_KIT_HEAD:+$GIT_PROMPT_KIT_HEAD }'
71+
72+
# prompt char
6373
PROMPT+='%F{%(?.$prompt_success_color.$prompt_failure_color)}%(!.#.$)%f '
6474
```
6575

6676
Using Git Prompt Kit's prompt character component leaves it all cleaned up.
6777

6878
```shell
6979
# ~/.zshrc
70-
# optional
71-
GIT_PROMPT_KIT_COLOR_CWD=#
72-
# optional
73-
GIT_PROMPT_KIT_COLOR_FAILED=#
74-
# optional
75-
GIT_PROMPT_KIT_COLOR_HEAD=#
76-
# optional
77-
GIT_PROMPT_KIT_COLOR_SUCCEEDED=#
78-
# load Git Prompt Kit
80+
81+
# load Git Prompt Kit and then
82+
7983
PROMPT='$GIT_PROMPT_KIT_CWD '
8084
PROMPT+='${GIT_PROMPT_KIT_HEAD:+$GIT_PROMPT_KIT_HEAD }'
8185
PROMPT+='$GIT_PROMPT_KIT_CHAR '
8286
```
8387

84-
In the above examples, the entire prompt could be built out of Git Prompt Kit components. But as the middle two show, using Git Prompt Kit components doesn't limit you to _only_ using Git Prompt Kit components. Say for example you wanted to add the time, and to put the prompt character on its own line. Do just as you would if you didn't have Git Prompt Kit:
88+
:::tip
89+
The above examples use [Git Prompt Kit's default colors](/options.html#color-options). But they can all be customized to your liking:
90+
91+
```shell
92+
GIT_PROMPT_KIT_COLOR_CWD=your_value_here
93+
GIT_PROMPT_KIT_COLOR_FAILED=your_value_here
94+
GIT_PROMPT_KIT_COLOR_HEAD=your_value_here
95+
GIT_PROMPT_KIT_COLOR_SUCCEEDED=your_value_here
96+
```
97+
98+
:::
99+
100+
Using Git Prompt Kit components doesn't limit you to _only_ using Git Prompt Kit components. Say for example you wanted to add the time, a note, and to put the prompt character on its own line. Do just as you would if you didn't have Git Prompt Kit:
85101

86102
```shell
87-
PROMPT='%* '
103+
# ~/.zshrc
104+
105+
set_prompt_vars() {
106+
typeset -g MY_COOL_PROMPT_CONTENT=your_value_here
107+
}
108+
109+
autoload -Uz add-zsh-hook
110+
add-zsh-hook precmd set_prompt_vars
111+
112+
# load Git Prompt Kit and then
113+
114+
PROMPT='%* hello world ${MY_COOL_PROMPT_CONTENT:+$MY_COOL_PROMPT_CONTENT }'
88115
PROMPT+='$GIT_PROMPT_KIT_CWD'
89116
PROMPT+='${GIT_PROMPT_KIT_HEAD:+ $GIT_PROMPT_KIT_HEAD}'
90117
PROMPT+=$'\n'

0 commit comments

Comments
 (0)