You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/usage.md
+65-38
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,36 @@
1
1
# Usage
2
2
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.
4
4
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.
6
6
7
7
:::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
+
:::
15
10
16
11
```shell
17
12
# ~/.zshrc
13
+
18
14
set_prompt_vars() {
19
15
# define prompt_git_head
20
16
# define prompt_git_dirty only if the working tree is dirty
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.
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:
85
101
86
102
```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 }'
0 commit comments