93c00cced5e248309986a7ac5cc4c48ad1f0c092
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
Merge pull request #4451 from victor-torres/branch-plugin
Add branch plugin
Diff
1diff --git a/plugins/branch/README.md b/plugins/branch/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..56ab8da4b4c8e1a1989c6d03c28138260e3c73f4
4--- /dev/null
5+++ b/plugins/branch/README.md
6@@ -0,0 +1,33 @@
7+# Branch
8+
9+Displays the current Git or Mercurial branch fast.
10+
11+## Speed test
12+
13+### Mercurial
14+
15+```shell
16+$ time hg branch
17+0.11s user 0.14s system 70% cpu 0.355 total
18+```
19+
20+### Branch plugin
21+
22+```shell
23+$ time zsh /tmp/branch_prompt_info_test.zsh
24+0.00s user 0.01s system 78% cpu 0.014 total
25+```
26+
27+## Usage
28+
29+Edit your theme file (eg.: `~/.oh-my-zsh/theme/robbyrussell.zsh-theme`)
30+adding `$(branch_prompt_info)` in your prompt like this:
31+
32+```diff
33+- PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
34++ PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)$(branch_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
35+```
36+
37+## Maintainer
38+
39+Victor Torres (<vpaivatorres@gmail.com>)
40diff --git a/plugins/branch/branch.plugin.zsh b/plugins/branch/branch.plugin.zsh
41new file mode 100644
42index 0000000000000000000000000000000000000000..a1e9ca31be4fbe016fa8470294868b5f4ceae294
43--- /dev/null
44+++ b/plugins/branch/branch.plugin.zsh
45@@ -0,0 +1,26 @@
46+# Branch: displays the current Git or Mercurial branch fast.
47+# Victor Torres <vpaivatorres@gmail.com>
48+# Oct 2, 2015
49+
50+function branch_prompt_info() {
51+ # Defines path as current directory
52+ local current_dir=$PWD
53+ # While current path is not root path
54+ while [[ $current_dir != '/' ]]
55+ do
56+ # Git repository
57+ if [[ -d "${current_dir}/.git" ]]
58+ then
59+ echo '±' ${"$(<"$current_dir/.git/HEAD")"##*/}
60+ return;
61+ fi
62+ # Mercurial repository
63+ if [[ -d "${current_dir}/.hg" ]]
64+ then
65+ echo '☿' $(<"$current_dir/.hg/branch")
66+ return;
67+ fi
68+ # Defines path as parent directory and keeps looking for :)
69+ current_dir="${current_dir:h}"
70+ done
71+}