From 9b0560257247887d716fbed36c43a32a97ed6ffd Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Sat, 7 Nov 2009 16:40:05 +0100 Subject: Better hg VCS prompt support. --- .zsh/functions/VCS_INFO_get_data_hg | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .zsh/functions/VCS_INFO_get_data_hg (limited to '.zsh/functions') diff --git a/.zsh/functions/VCS_INFO_get_data_hg b/.zsh/functions/VCS_INFO_get_data_hg new file mode 100644 index 0000000..d92d83a --- /dev/null +++ b/.zsh/functions/VCS_INFO_get_data_hg @@ -0,0 +1,76 @@ +## vim:ft=zsh +## mercurial support by: Frank Terbeck +## Distributed under the same BSD-ish license as zsh itself. + +setopt localoptions NO_shwordsplit +local file hgbranch hgbranch_name hgbase hghash hglrev hgmisc r_branch r_info revformat +local hgunstaged + +VCS_INFO_hg_get_mq_top_patch () { + local patchdir=$1 + + if [[ -e "${patchdir}/status" ]]; then + local -a patches + patches=(${(f)"$(< "${patchdir}/status")"}) + printf "%s" "${patches[-1]/[^:]*:/}" + return 0 + fi + + return 1 +} + + +hgbase=${vcs_comm[basedir]} +rrn=${hgbase:t} + +file="${hgbase}/.hg/branch" +if [[ -r ${file} ]] ; then + hgbranch_name=$(< ${file}) +else + hgbranch_name="default" +fi + +hghash='' +hglrev='' +if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then + # Calling the 'hg' program is quite a bit too slow for prompts. + # If there's a way around that, I'd be interested. + # Disabled by default anyway, so no harm done. + + HGRCPATH="/dev/null" ${vcs_comm[cmd]} branches \ + | while read -r r_branch r_info ; do + if [[ ${r_branch} == ${hgbranch_name} ]] ; then + match=() + : ${r_info/(#b)([^:]##):(*)} + hglrev=${match[1]} + hghash=${match[2]} + break + fi + done + + if [[ -n ${hglrev} ]] ; then + zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" hgrevformat revformat || revformat="%r:%h" + zformat -f hglrev "${revformat}" "r:${hglrev}" "h:${hghash}" + zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat hgbranch || hgbranch="%b:%r" + zformat -f hgbranch "${hgbranch}" "b:${hgbranch_name}" "r:${hglrev}" + fi + + if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then + [[ -n $(${vcs_comm[cmd]} status -q 2> /dev/null) ]] && hgunstaged=1 + fi +else + hgbranch="${hgbranch_name}" +fi + +local patchdir=${hgbase}/.hg/patches/ + +if [[ -d $patchdir ]] ; then + hgmisc=$(VCS_INFO_hg_get_mq_top_patch "${patchdir}") + + hgmisc=${hgmisc:-"no patch applied"} +else + hgmisc='' +fi + +VCS_INFO_formats '' "${hgbranch}" "${hgbase}" '' "${hgunstaged}" "${hglrev}" "${hgmisc}" +return 0 -- cgit v1.2.3-54-g00ecf