Merge pull request #4451 from victor-torres/branch-plugin

Add branch plugin
This commit is contained in:
Marc Cornellà 2015-12-15 01:02:49 +01:00
commit 93c00cced5
2 changed files with 59 additions and 0 deletions

33
plugins/branch/README.md Normal file
View File

@ -0,0 +1,33 @@
# Branch
Displays the current Git or Mercurial branch fast.
## Speed test
### Mercurial
```shell
$ time hg branch
0.11s user 0.14s system 70% cpu 0.355 total
```
### Branch plugin
```shell
$ time zsh /tmp/branch_prompt_info_test.zsh
0.00s user 0.01s system 78% cpu 0.014 total
```
## Usage
Edit your theme file (eg.: `~/.oh-my-zsh/theme/robbyrussell.zsh-theme`)
adding `$(branch_prompt_info)` in your prompt like this:
```diff
- PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
+ PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)$(branch_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
```
## Maintainer
Victor Torres (<vpaivatorres@gmail.com>)

View File

@ -0,0 +1,26 @@
# Branch: displays the current Git or Mercurial branch fast.
# Victor Torres <vpaivatorres@gmail.com>
# Oct 2, 2015
function branch_prompt_info() {
# Defines path as current directory
local current_dir=$PWD
# While current path is not root path
while [[ $current_dir != '/' ]]
do
# Git repository
if [[ -d "${current_dir}/.git" ]]
then
echo '±' ${"$(<"$current_dir/.git/HEAD")"##*/}
return;
fi
# Mercurial repository
if [[ -d "${current_dir}/.hg" ]]
then
echo '☿' $(<"$current_dir/.hg/branch")
return;
fi
# Defines path as parent directory and keeps looking for :)
current_dir="${current_dir:h}"
done
}