From d36797693291a89b2d04d59723ef967caab97d2d Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 22 Apr 2013 19:07:34 +0200 Subject: [PATCH] Add a special mark when in a disabled VCS repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds the LP_MARK_DISABLED (default: "⌀"), used as a prompt mark when in disabled repositories (see `LP_DISABLED_VCS_PATH`). --- README.md | 1 + liquidprompt | 54 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d7fea33..ce269a4 100644 --- a/README.md +++ b/README.md @@ -297,6 +297,7 @@ Special characters: * `LP_MARK_GIT` (default: "±") prompt mark in git repositories * `LP_MARK_FOSSIL` (default: "⌘") prompt mark in fossil repositories * `LP_MARK_BZR` (default: "⚯") prompt mark in bazaar repositories +* `LP_MARK_DISABLED` (default: "⌀") prompt mark in disabled repositories (see `LP_DISABLED_VCS_PATH`) * `LP_MARK_UNTRACKED` (default: "*") if git has untracked files * `LP_MARK_STASH` (default: "+") if git has stashed modifications * `LP_MARK_BRACKET_OPEN` (default: "[") marks around the main part of the prompt diff --git a/liquidprompt b/liquidprompt index 5c68960..7059fae 100755 --- a/liquidprompt +++ b/liquidprompt @@ -237,6 +237,7 @@ _lp_source_config() LP_MARK_GIT=${LP_MARK_GIT:-"±"} LP_MARK_FOSSIL=${LP_MARK_FOSSIL:-"⌘"} LP_MARK_BZR=${LP_MARK_BZR:-"⚯"} + LP_MARK_DISABLED=${LP_MARK_DISABLED:-"⌀"} LP_MARK_UNTRACKED=${LP_MARK_UNTRACKED:-"*"} LP_MARK_STASH=${LP_MARK_STASH:-"+"} LP_MARK_BRACKET_OPEN=${LP_MARK_BRACKET_OPEN:-"["} @@ -1274,6 +1275,8 @@ _lp_smart_mark() mark=$LP_MARK_FOSSIL elif [[ "$1" == "bzr" ]]; then mark=$LP_MARK_BZR + elif [[ "$1" == "disabled" ]]; then + mark=$LP_MARK_DISABLED fi echo -ne "${COL}${mark}${NO_COL}" } @@ -1382,8 +1385,10 @@ _lp_set_prompt() # right of main prompt: space at left LP_VENV=$(_lp_sl "$(_lp_virtualenv)") - LP_VCS="" + # if change of working directory if [[ "$LP_OLD_PWD" != "$PWD" ]]; then + LP_VCS="" + LP_VCS_TYPE="" # LP_HOST is a global set at load time LP_PERM=$(_lp_permissions_color) LP_PWD=$(_lp_shorten_path) @@ -1391,38 +1396,47 @@ _lp_set_prompt() if [[ "$(_lp_are_vcs_disabled)" -eq "0" ]] ; then LP_VCS="$(_lp_git_branch_color)" - LP_VCS_TYPES="git" + LP_VCS_TYPE="git" if [[ -n "$LP_VCS" ]]; then # If this is a git-svn repository if [[ -d "$(git rev-parse --git-dir 2>/dev/null)/svn" ]]; then - LP_VCS_TYPES="git-svn" + LP_VCS_TYPE="git-svn" fi fi # git-svn if [[ -z "$LP_VCS" ]]; then LP_VCS="$(_lp_hg_branch_color)" - LP_VCS_TYPES="hg" + LP_VCS_TYPE="hg" if [[ -z "$LP_VCS" ]]; then LP_VCS="$(_lp_svn_branch_color)" - LP_VCS_TYPES="svn" + LP_VCS_TYPE="svn" if [[ -z "$LP_VCS" ]]; then LP_VCS="$(_lp_fossil_branch_color)" - LP_VCS_TYPES="fossil" + LP_VCS_TYPE="fossil" if [[ -z "$LP_VCS" ]]; then LP_VCS="$(_lp_bzr_branch_color)" - LP_VCS_TYPES="bzr" + LP_VCS_TYPE="bzr" + if [[ -z "$LP_VCS" ]]; then + LP_VCS="" + LP_VCS_TYPE="" + fi # nothing fi # bzr fi # fossil fi # svn fi # hg - fi # disabled - if [[ -z "$LP_VCS" ]] ; then - LP_VCS_TYPES="" + + else # if this vcs rep is disabled + LP_VCS="" # not necessary, but more readable + LP_VCS_TYPE="disabled" + fi + + if [[ -z "$LP_VCS_TYPE" ]] ; then + LP_VCS="" else LP_VCS=$(_lp_sl "${LP_VCS}") fi # end of the prompt line: double spaces - LP_MARK=$(_lp_sb "$(_lp_smart_mark $LP_VCS_TYPES)") + LP_MARK=$(_lp_sb "$(_lp_smart_mark $LP_VCS_TYPE)") # Different path color if root if [[ "$EUID" -ne "0" ]] ; then @@ -1432,14 +1446,16 @@ _lp_set_prompt() fi LP_OLD_PWD="$PWD" - elif [[ -n "$LP_VCS_TYPES" ]]; then - case "$LP_VCS_TYPES" in - git) LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");; - git-svn)LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");; - hg) LP_VCS=$(_lp_sl "$(_lp_hg_branch_color)");; - svn) LP_VCS=$(_lp_sl "$(_lp_svn_branch_color)");; - fossil) LP_VCS=$(_lp_sl "$(_lp_fossil_branch_color)");; - bzr) LP_VCS=$(_lp_sl "$(_lp_bzr_branch_color)");; + # if do not change of working directory but... + elif [[ -n "$LP_VCS_TYPE" ]]; then # we are still in a VCS dir + case "$LP_VCS_TYPE" in + git) LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");; + git-svn) LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");; + hg) LP_VCS=$(_lp_sl "$(_lp_hg_branch_color)");; + svn) LP_VCS=$(_lp_sl "$(_lp_svn_branch_color)");; + fossil) LP_VCS=$(_lp_sl "$(_lp_fossil_branch_color)");; + bzr) LP_VCS=$(_lp_sl "$(_lp_bzr_branch_color)");; + disabled)LP_VCS="";; esac fi