This commit is contained in:
Creak 2018-02-18 23:06:57 +00:00 committed by GitHub
commit a49c90ea42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,24 +18,60 @@ alias hgca='hg commit --amend'
# list unresolved files (since hg does not list unmerged files in the status command) # list unresolved files (since hg does not list unmerged files in the status command)
alias hgun='hg resolve --list' alias hgun='hg resolve --list'
# Configuration
# Comment this line if you don't want to show if the branch is dirty or not.
# This can save a lot of time of very large repositories.
SHOW_DIRTY_BRANCH=1
function hg_get_dir() {
# Defines path as current directory
local current_dir=$PWD
# While current path is not root path
while [[ $current_dir != '/' ]]; do
if [[ -d "${current_dir}/.hg" ]]; then
echo "${current_dir}/.hg"
return
fi
# Defines path as parent directory and keeps looking for
current_dir="${current_dir:h}"
done
}
function in_hg() { function in_hg() {
if [[ -d .hg ]] || $(hg summary > /dev/null 2>&1); then if [[ $(hg_get_dir) != "" ]]; then
echo 1 echo 1
fi fi
} }
function hg_get_branch_id() {
local hg_id_tip=`hg log -T "{node|short}" -l 1 -b .`
local hg_id=`hg id -i -r .`
if [[ $hg_id != $hg_id_tip ]]; then
echo "@${hg_id}"
fi
}
function hg_get_branch_name() { function hg_get_branch_name() {
if [ $(in_hg) ]; then local hg_dir=$(hg_get_dir)
echo $(hg branch) if [[ $hg_dir != "" ]]; then
local hg_id=$(hg_get_branch_id)
if [[ -f "${hg_dir}/branch" ]]; then
echo $(<"${hg_dir}/branch")$hg_id
else
echo "default${hg_id}"
fi
fi fi
} }
function hg_prompt_info { function hg_prompt_info {
if [ $(in_hg) ]; then local branch=$(hg_get_branch_name)
_DISPLAY=$(hg_get_branch_name) if [[ $branch != "" ]]; then
echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_PREFIX\ if [[ $SHOW_DIRTY_BRANCH == 1 ]]; then
$ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_PROMPT_BASE_COLOR$(hg_dirty)$ZSH_THEME_HG_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR" branch="${branch}$(hg_dirty)"
unset _DISPLAY fi
echo "$ZSH_THEME_HG_PROMPT_PREFIX${branch}$ZSH_THEME_HG_PROMPT_SUFFIX"
fi fi
} }
@ -57,9 +93,9 @@ function hg_dirty {
} }
function hgic() { function hgic() {
hg incoming "$@" | grep "changeset" | wc -l hg incoming "$@" | grep "changeset" | wc -l
} }
function hgoc() { function hgoc() {
hg outgoing "$@" | grep "changeset" | wc -l hg outgoing "$@" | grep "changeset" | wc -l
} }