summaryrefslogtreecommitdiff
path: root/oh-my-zsh/plugins/branch
diff options
context:
space:
mode:
authorAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
committerAditya <bluenerd@protonmail.com>2023-02-27 20:04:56 +0530
commitedc449275b6c04445f58b108ca0937a87c1e8430 (patch)
tree9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/branch
parent6f5424ca96c4221ef433f545642669e9c104d0ed (diff)
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/branch')
-rw-r--r--oh-my-zsh/plugins/branch/README.md49
-rw-r--r--oh-my-zsh/plugins/branch/branch.plugin.zsh35
2 files changed, 84 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/branch/README.md b/oh-my-zsh/plugins/branch/README.md
new file mode 100644
index 0000000..a15dd22
--- /dev/null
+++ b/oh-my-zsh/plugins/branch/README.md
@@ -0,0 +1,49 @@
+# Branch plugin
+
+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
+
+- `hg branch`:
+
+ ```console
+ $ time hg branch
+ 0.11s user 0.14s system 70% cpu 0.355 total
+ ```
+
+- branch plugin:
+
+ ```console
+ $ time zsh /tmp/branch_prompt_info_test.zsh
+ 0.00s user 0.01s system 78% cpu 0.014 total
+ ```
+
+## Usage
+
+Copy your theme to `$ZSH_CUSTOM/themes/` and modify it to add `$(branch_prompt_info)` in your prompt.
+This example is for the `robbyrussell` theme:
+
+```diff
+diff --git a/themes/robbyrussell.zsh-theme b/themes/robbyrussell.zsh-theme
+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
+
+Victor Torres (<vpaivatorres@gmail.com>)
diff --git a/oh-my-zsh/plugins/branch/branch.plugin.zsh b/oh-my-zsh/plugins/branch/branch.plugin.zsh
new file mode 100644
index 0000000..dd5871f
--- /dev/null
+++ b/oh-my-zsh/plugins/branch/branch.plugin.zsh
@@ -0,0 +1,35 @@
+# Branch: displays the current Git or Mercurial branch fast.
+# Victor Torres <vpaivatorres@gmail.com>
+# Oct 2, 2015
+
+function branch_prompt_info() {
+ # Start checking in current working directory
+ local branch="" dir="$PWD"
+ while [[ "$dir" != '/' ]]; do
+ # Found .git directory
+ if [[ -d "${dir}/.git" ]]; then
+ branch="${"$(<"${dir}/.git/HEAD")"##*/}"
+ echo '±' "${branch:gs/%/%%}"
+ return
+ fi
+
+ # Found .hg directory
+ if [[ -d "${dir}/.hg" ]]; then
+ if [[ -f "${dir}/.hg/branch" ]]; then
+ branch="$(<"${dir}/.hg/branch")"
+ else
+ branch="default"
+ fi
+
+ if [[ -f "${dir}/.hg/bookmarks.current" ]]; then
+ branch="${branch}/$(<"${dir}/.hg/bookmarks.current")"
+ fi
+
+ echo '☿' "${branch:gs/%/%%}"
+ return
+ fi
+
+ # Check parent directory
+ dir="${dir:h}"
+ done
+}