diff --git a/bashrc b/bashrc index 5f76794..b5e7eb0 100644 --- a/bashrc +++ b/bashrc @@ -125,7 +125,7 @@ fi export PATH MANPATH # Base functions ready. Let's load bashrc.d. -for script in /etc/bashrc.d/*; do . "$script"; done +for script in /etc/bashrc.d/!(_vcs); do . "$script"; done # The prompt depends on vcs_status! Get one backup anyway. type _vcs_status &>/dev/null || \ diff --git a/bashrc.d/20-vcs b/bashrc.d/20-vcs.sh similarity index 60% rename from bashrc.d/20-vcs rename to bashrc.d/20-vcs.sh index 19c9a2a..5e85a85 100644 --- a/bashrc.d/20-vcs +++ b/bashrc.d/20-vcs.sh @@ -1,4 +1,4 @@ -# 20-vcs, the version control display for AOSC OSes PS1. +# 20-vcs, the version control display for AOSC OS PS1. # by Arthur Wang # This module is highly extensible. Just read the source. @@ -8,18 +8,17 @@ _is_posix && return # Get functions -_vcs_files="$(echo /etc/bashrc.d/.vcs_*)" -if [ "$_vcs_files" == "/etc/bashrc.d/.vcs_*" ]; then +if [ -e /etc/bashrc.d/_vcs ]; then + for _vcs in /etc/bashrc.d/_vcs/*; do + . "$_vcs" + _vcs_mods+=" $(basename ${_vcs})" + done +else _vcs_status(){ true; } unset _vcs_files return -else - for _vcs in $_vcs_files; do - . "$_vcs" - _vcs_mods+=" ${_vcs/\/etc\/bashrc.d\/.vcs_}" - done fi -unset _vcs _vcs_files +unset _vcs # Output _vcs_status() { diff --git a/bashrc.d/.vcs_git b/bashrc.d/_vcs/git similarity index 96% rename from bashrc.d/.vcs_git rename to bashrc.d/_vcs/git index c7f62e3..8430473 100644 --- a/bashrc.d/.vcs_git +++ b/bashrc.d/_vcs/git @@ -37,6 +37,9 @@ _ps1_git_status() { local bgs bgs=$(bash-git-status) case "$?" in + 1) + return 1 + ;; 5) echo -e "\01\e[1m\02@\01\e[0;32m\0002$bgs\01\e[0m\02" ;; diff --git a/bashrc.d/.vcs_hg b/bashrc.d/_vcs/hg similarity index 51% rename from bashrc.d/.vcs_hg rename to bashrc.d/_vcs/hg index 8e44417..1aeb5d3 100644 --- a/bashrc.d/.vcs_hg +++ b/bashrc.d/_vcs/hg @@ -16,11 +16,18 @@ alias ha='hg add .' # From http://mediadoneright.com/content/ultimate-git-ps1-bash-prompt # Modified for hg. _ps1_hg_status() { - hg branch &>/dev/null || return 1 - if LC_ALL=C hg status | grep -q ' '; then - echo -ne "@\01\e[1m\]\01\e[0;32m\]$(hg branch)\01\e[0m\]" + # skip the check if possible, because hg is slow. + test -e .hg || return 1 + hgb=$(hg branch 2>/dev/null) || return 1 + hgs=$(LC_ALL=C hg status 2>&1) + if [ -z "$hgs" ]; then # unmodified + echo -e "\01\e[1m\02@\01\e[0;32m\0002$hgb\01\e[0m\02" + elif printf %s "$hgs" | grep -q '^[M!]'; then # modified or deleted + echo -e "\01\e[1m\02@\01$IRED\0002$hgb\01\e[0m\02" + elif printf %s "$hgs" | grep -q '^?'; then # untracked + echo -e "\01\e[1m\02@\01\e[0;35m\0002$hgb\01\e[0m\02" else - echo -ne "@\01\e[1m\]\01$IRED\]$(hg branch)\01\e[0m\]" + echo -e "\01\e[1m\02@\01\e[0;37m\0002$hgb\01\e[0m\02" fi }