Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
46e63340
Unverified
Commit
46e63340
authored
Dec 01, 2021
by
whoami
Committed by
GitHub
Dec 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(branch): show mercurial bookmarks if used (#9948)
Co-authored-by:
Marc Cornellà
<
hello@mcornella.com
>
parent
c66fc004
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
36 deletions
+56
-36
README.md
plugins/branch/README.md
+32
-16
branch.plugin.zsh
plugins/branch/branch.plugin.zsh
+24
-20
No files found.
plugins/branch/README.md
View file @
46e63340
# Branch
# Branch
plugin
Displays the current Git or Mercurial branch fast.
This plugin displays the current Git or Mercurial branch, fast. If in a Mercurial repository,
also display the current bookmark, if present.
To use it, add
`branch`
to the plugins array in your zshrc file:
```
zsh
plugins
=(
... branch
)
```
## Speed test
## Speed test
### Mercurial
-
`hg branch`
:
```
shell
```
console
$
time
hg branch
$
time
hg branch
0.11s user 0.14s system 70% cpu 0.355 total
0.11s user 0.14s system 70% cpu 0.355 total
```
```
### Branch plugin
- branch plugin:
```
shell
```console
$
time
zsh /tmp/branch_prompt_info_test.zsh
$
time
zsh /tmp/branch_prompt_info_test.zsh
0.00s user 0.01s system 78% cpu 0.014 total
0.00s user 0.01s system 78% cpu 0.014 total
```
```
#
# Usage
#
# Usage
Edit your theme file (eg.:
`~/.oh-my-zsh/theme/robbyrussell.zsh-theme`
)
Copy your theme to `$
ZSH_CUSTOM/themes/
`
and modify it to add
`
$(
branch_prompt_info
)
`
in
your prompt.
adding
`$(branch_prompt_info)`
in your prompt like this
:
This example is for the `robbyrussell` theme
:
```
diff
```
diff
- PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
diff --git a/themes/robbyrussell.zsh-theme b/themes/robbyrussell.zsh-theme
+ PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)$(branch_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
index 2fd5f2cd..9d89a464 100644
--- a/themes/robbyrussell.zsh-theme
+++ b/themes/robbyrussell.zsh-theme
@@ -1,5 +1,5 @@
PROMPT="%(?:%{$fg_bold
[
green
]
%}➜ :%{$fg_bold
[
red
]
%}➜ )"
-PROMPT+=' %{$fg
[
cyan
]
%}%c%{$reset_color%} $(git_prompt_info)'
+PROMPT+=' %{$fg
[
cyan
]
%}%c%{$reset_color%} $(branch_prompt_info)'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold
[
blue
]
%}git:(%{$fg
[
red
]
%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
```
```
## Maintainer
## Maintainer
...
...
plugins/branch/branch.plugin.zsh
View file @
46e63340
...
@@ -3,29 +3,33 @@
...
@@ -3,29 +3,33 @@
# Oct 2, 2015
# Oct 2, 2015
function
branch_prompt_info
()
{
function
branch_prompt_info
()
{
# Defines path as current directory
# Start checking in current working directory
local
current_dir
=
$PWD
local
branch
=
""
dir
=
"
$PWD
"
# While current path is not root path
while
[[
"
$dir
"
!=
'/'
]]
;
do
while
[[
$current_dir
!=
'/'
]]
# Found .git directory
do
if
[[
-d
"
${
dir
}
/.git"
]]
;
then
# Git repository
branch
=
"
${
"
$(
<
"
${
dir
}
/.git/HEAD"
)
"
##*/
}
"
if
[[
-d
"
${
current_dir
}
/.git"
]]
echo
'±'
"
${
branch
:gs/%/%%
}
"
then
return
echo
'±'
${
"
$(
<
"
$current_dir
/.git/HEAD"
)
"
##*/
}
return
;
fi
fi
# Mercurial repository
if
[[
-d
"
${
current_dir
}
/.hg"
]]
# Found .hg directory
then
if
[[
-d
"
${
dir
}
/.hg"
]]
;
then
if
[[
-f
"
$current_dir
/.hg/branch"
]]
if
[[
-f
"
${
dir
}
/.hg/branch"
]]
;
then
then
branch
=
"
$(
<
"
${
dir
}
/.hg/branch"
)
"
echo
'☿'
$(
<
"
$current_dir
/.hg/branch"
)
else
else
echo
'☿ default'
branch
=
"default"
fi
if
[[
-f
"
${
dir
}
/.hg/bookmarks.current"
]]
;
then
branch
=
"
${
branch
}
/
$(
<
"
${
dir
}
/.hg/bookmarks.current"
)
"
fi
fi
return
;
echo
'☿'
"
${
branch
:gs/%/%%
}
"
return
fi
fi
# Defines path as parent directory and keeps looking for :)
current_dir
=
"
${
current_dir
:h
}
"
# Check parent directory
dir
=
"
${
dir
:h
}
"
done
done
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment