1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-23 14:20:08 +00:00
ohmyzsh/plugins/branch/branch.plugin.zsh

32 lines
787 B
Bash
Raw Normal View History

2015-10-03 02:16:56 +00:00
# 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
2015-10-03 02:16:56 +00:00
# While current path is not root path
while [[ $current_dir != '/' ]]
2015-10-03 02:16:56 +00:00
do
# Git repository
if [[ -d "${current_dir}/.git" ]]
2015-10-03 02:16:56 +00:00
then
echo '±' ${"$(<"$current_dir/.git/HEAD")"##*/}
2015-10-03 02:16:56 +00:00
return;
fi
# Mercurial repository
if [[ -d "${current_dir}/.hg" ]]
2015-10-03 02:16:56 +00:00
then
if [[ -f "$current_dir/.hg/branch" ]]
then
echo '☿' $(<"$current_dir/.hg/branch")
else
echo '☿ default'
fi
2015-10-03 02:16:56 +00:00
return;
fi
# Defines path as parent directory and keeps looking for :)
current_dir="${current_dir:h}"
2015-10-03 02:16:56 +00:00
done
}