Skip to content

Commit 6c452e3

Browse files
committed
Merge pull request #440 from danielshahaf/i422-v2
zsh += vcs_info and native completion
2 parents 5cb9bdd + 42891b4 commit 6c452e3

File tree

1 file changed

+19
-7
lines changed
  • book/A-git-in-other-environments/sections

1 file changed

+19
-7
lines changed

book/A-git-in-other-environments/sections/zsh.asc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
=== Git in Zsh
22

33
(((zsh)))(((tab completion, zsh)))(((shell prompts, zsh)))
4-
Git also ships with a tab-completion library for Zsh.
5-
Just copy `contrib/completion/git-completion.zsh` to your home directory and source it from your `.zshrc`.
4+
Zsh also ships with a tab-completion library for Git.
5+
To use it, simply run `autoload -Uz compinit && compinit` in your `.zshrc`.
66
Zsh's interface is a bit more powerful than Bash's:
77

88
[source,console]
@@ -17,24 +17,36 @@ cherry-pick -- apply changes introduced by some existing commits
1717
----
1818

1919
Ambiguous tab-completions aren't just listed; they have helpful descriptions, and you can graphically navigate the list by repeatedly hitting tab.
20-
This works with Git commands, their arguments, and names of things inside the repository (like refs and remotes), as well filenames and all the other things Zsh knows how to tab-complete.
20+
This works with Git commands, their arguments, and names of things inside the repository (like refs and remotes), as well as filenames and all the other things Zsh knows how to tab-complete.
2121

22-
Zsh happens to be fairly compatible with Bash when it comes to prompt customization, but it allows you to have a right-side prompt as well.
23-
To include the branch name on the right side, add these lines to your `~/.zshrc` file:
22+
Zsh ships with a framework for getting information from version control systems, called `vcs_info`.
23+
To include the branch name in the prompt on the right side, add these lines to your `~/.zshrc` file:
2424

2525
[source,console]
2626
----
27+
autoload -Uz vcs_info
28+
precmd_vcs_info() { vcs_info }
29+
precmd_functions+=( precmd_vcs_info )
2730
setopt prompt_subst
28-
. ~/git-prompt.sh
29-
export RPROMPT=$'$(__git_ps1 "%s")'
31+
RPROMPT=\$vcs_info_msg_0_
32+
# PROMPT=\$vcs_info_msg_0_'%# '
33+
zstyle ':vcs_info:git:*' formats '%b'
3034
----
3135

3236
This results in a display of the current branch on the right-hand side of the terminal window, whenever your shell is inside a Git repository.
37+
(The left side is supported as well, of course; just uncomment the assignment to PROMPT.)
3338
It looks a bit like this:
3439

3540
.Customized `zsh` prompt.
3641
image::images/zsh-prompt.png[Customized `zsh` prompt.]
3742

43+
For more information on vcs_info, check out its documentation
44+
in the `zshcontrib(1)` manual page,
45+
or online at http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information[].
46+
47+
Instead of vcs_info, you might prefer the prompt customization script that ships with Git, called `git-prompt.sh`; see http://git-prompt.sh[] for details.
48+
`git-prompt.sh` is compatible with both Bash and Zsh.
49+
3850
Zsh is powerful enough that there are entire frameworks dedicated to making it better.
3951
One of them is called "oh-my-zsh", and it can be found at https://github.com/robbyrussell/oh-my-zsh[].
4052
oh-my-zsh's plugin system comes with powerful git tab-completion, and it has a variety of prompt "themes", many of which display version-control data.

0 commit comments

Comments
 (0)