Improve mercurial prompt

This commit is contained in:
Creak 2018-02-18 18:06:05 -05:00 committed by GitHub
parent 3ee22a4ebc
commit 24a7aeb8bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,12 @@ 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() { function hg_get_dir() {
# Defines path as current directory # Defines path as current directory
local current_dir=$PWD local current_dir=$PWD
@ -38,13 +44,23 @@ function in_hg() {
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() {
local hg_dir=$(hg_get_dir) local hg_dir=$(hg_get_dir)
if [[ $hg_dir != "" ]]; then if [[ $hg_dir != "" ]]; then
local hg_id=$(hg_get_branch_id)
if [[ -f "${hg_dir}/branch" ]]; then if [[ -f "${hg_dir}/branch" ]]; then
echo $(<"${hg_dir}/branch") echo $(<"${hg_dir}/branch")$hg_id
else else
echo "default" echo "default${hg_id}"
fi fi
fi fi
} }
@ -52,10 +68,11 @@ function hg_get_branch_name() {
function hg_prompt_info { function hg_prompt_info {
local branch=$(hg_get_branch_name) local branch=$(hg_get_branch_name)
if [[ $branch != "" ]]; then 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\ branch="${branch}$(hg_dirty)"
$ZSH_PROMPT_BASE_COLOR$(hg_dirty)$ZSH_THEME_HG_PROMPT_SUFFIX\ fi
$ZSH_PROMPT_BASE_COLOR" echo "$ZSH_THEME_HG_PROMPT_PREFIX${branch}$ZSH_THEME_HG_PROMPT_SUFFIX"
fi
} }
function hg_dirty_choose { function hg_dirty_choose {