From 194c5b1ca3a10bc8ef3933fd6d5f60df5f4c6665 Mon Sep 17 00:00:00 2001 From: Michele Bologna Date: Tue, 22 Sep 2015 16:36:31 +0200 Subject: [PATCH] Added mercurial library The added library parses output of the hg (mercurial) command, and outputs the same variables (which should be customized by theme) in your prompt. I added an example of these variables to michelebologna theme. This patch should uniform all the behaviour of all themes regarding mercurial. In fact, some themes implement their own hg parsing *inside* the theme. This should be better implemented in a library, as happens with git library. --- lib/mercurial.zsh | 32 ++++++++++++++++++++++++++++++++ lib/prompt_info_functions.zsh | 2 +- themes/michelebologna.zsh-theme | 6 ++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lib/mercurial.zsh diff --git a/lib/mercurial.zsh b/lib/mercurial.zsh new file mode 100644 index 00000000..73fedcde --- /dev/null +++ b/lib/mercurial.zsh @@ -0,0 +1,32 @@ +# Michele Bologna +# +# Implements a hg_prompt_info function that inspect the current mercurial repo +# (if any) and then outputs the status of the repo, in a similar way with +# git.zsh library. +# +# themes should customize: +# * ZSH_THEME_HG_PROMPT_UNTRACKED - symbol to show in prompt if untracked +# files are present in the mercurial repo +# * ZSH_THEME_HG_PROMPT_ADDED - symbol to show in prompt if added files are +# present in the mercurial repo +# * ZSH_THEME_HG_PROMPT_MODIFIED - symbol to show in prompt if modified files +# are present in the mercurial repo + +hg_prompt_info() +{ + local STATUS="" + if $(hg id >/dev/null 2>&1); then + local BRANCH=$(hg branch 2>/dev/null) + if `hg status | grep -q "^\?"`; then + STATUS="$ZSH_THEME_HG_PROMPT_UNTRACKED" + fi + if `hg status | grep -q "^[A]"`; then + STATUS="$ZSH_THEME_HG_PROMPT_ADDED$STATUS" + fi + if `hg status | grep -q "^[M]"`; then + STATUS="$ZSH_THEME_HG_PROMPT_MODIFIED$STATUS" + fi + echo "$BRANCH$STATUS" + fi +} + diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 335c02a3..96441a0a 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -10,7 +10,7 @@ # Dummy implementations that return false to prevent command_not_found # errors with themes, that implement these functions # Real implementations will be used when the respective plugins are loaded -function chruby_prompt_info hg_prompt_info pyenv_prompt_info \ +function chruby_prompt_info pyenv_prompt_info \ rbenv_prompt_info svn_prompt_info vi_mode_prompt_info \ virtualenv_prompt_info { return 1 diff --git a/themes/michelebologna.zsh-theme b/themes/michelebologna.zsh-theme index 110e3f20..f9d479ca 100644 --- a/themes/michelebologna.zsh-theme +++ b/themes/michelebologna.zsh-theme @@ -68,8 +68,14 @@ ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE=">" ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE="<" ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE="$red<>" +ZSH_THEME_HG_PROMPT_MODIFIED="$red*" +ZSH_THEME_HG_PROMPT_ADDED="$green+" +ZSH_THEME_HG_PROMPT_UNTRACKED="$blue%%" + PROMPT='$username_output$hostname_output:$current_dir_output%1(j. [$jobs_bg].)' GIT_PROMPT='$(out=$(git_prompt_info)$(git_prompt_status)$(git_remote_status);if [[ -n $out ]]; then printf %s " $white($green$out$white)$reset";fi)' PROMPT+="$GIT_PROMPT" +HG_PROMPT='$(out=$(hg_prompt_info);if [[ -n $out ]]; then printf %s " $white($green$out$white)$reset";fi)' +PROMPT+="$HG_PROMPT" PROMPT+=" $last_command_output%#$reset " RPROMPT=''