Merge pull request #98 from jaesivsm/feature/vcs

Feature/vcs
This commit is contained in:
nojhan 2013-01-24 02:08:27 -08:00
commit 883901008b
4 changed files with 81 additions and 41 deletions

View File

@ -174,10 +174,7 @@ Available features:
* `LP_PERM` a colon ":" * `LP_PERM` a colon ":"
* `LP_PWD` current working directory * `LP_PWD` current working directory
* `LP_PROXY` HTTP proxy * `LP_PROXY` HTTP proxy
* `LP_GIT` git * `LP_VCS` informations concerning the current working repository
* `LP_HG` mercurial
* `LP_SVN` subversion
* `LP_FOSSIL` fossil
* `LP_ERR` last error code * `LP_ERR` last error code
* `LP_MARK` prompt mark * `LP_MARK` prompt mark
* `LP_TITLE` the prompt as a window's title escaped sequence * `LP_TITLE` the prompt as a window's title escaped sequence
@ -195,6 +192,7 @@ To erase your new formatting, just bring the `LP_PS1` to a null string:
export LP_PS1="" export LP_PS1=""
## THEMES ## THEMES
You can change the colors and special characters of some part of the liquid You can change the colors and special characters of some part of the liquid

View File

@ -12,9 +12,7 @@
# LP_PERM a colon ":" # LP_PERM a colon ":"
# LP_PWD current working directory # LP_PWD current working directory
# LP_PROXY HTTP proxy # LP_PROXY HTTP proxy
# LP_GIT git # LP_VCS the content of the current repository
# LP_HG mercurial
# LP_SVN subversion
# LP_ERR last error code # LP_ERR last error code
# LP_MARK prompt mark # LP_MARK prompt mark
# LP_TIME current time # LP_TIME current time
@ -34,13 +32,12 @@ then
# path in foreground color # path in foreground color
LP_PS1="${LP_PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}" LP_PS1="${LP_PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
# add VCS infos # add VCS infos
LP_PS1="${LP_PS1}${LP_GIT}${LP_HG}${LP_SVN}${LP_FOSSIL}" LP_PS1="${LP_PS1}${LP_VCS}"
else else
# path in yellow # path in yellow
LP_PS1="${LP_PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}" LP_PS1="${LP_PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
# do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT) # do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT)
[[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && \ [[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && LP_PS1="${LP_PS1}${LP_VCS}"
LP_PS1="${LP_PS1}${LP_GIT}${LP_HG}${LP_SVN}${LP_FOSSIL}"
fi fi
# add return code and prompt mark # add return code and prompt mark
LP_PS1="${LP_PS1}${LP_ERR}${LP_MARK}" LP_PS1="${LP_PS1}${LP_ERR}${LP_MARK}"

View File

@ -210,6 +210,7 @@ _lp_source_config()
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1} LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0} LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0} LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0}
LP_DISABLED_VCS_PATH=${LP_DISABLED_VCS_PATH:-""}
LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"} LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"}
LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"} LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"}
@ -624,13 +625,26 @@ _lp_return_value()
# VCS branch display # # VCS branch display #
###################### ######################
_lp_are_vcs_disabled()
{
[[ -z "$LP_DISABLED_VCS_PATH" ]] && echo 0 && return
local path
local IFS=:
for path in $LP_DISABLED_VCS_PATH; do
if [[ "$PWD" == *"$path"* ]]; then
echo 1
return
fi
done
echo 0
}
# GIT # # GIT #
# Get the branch name of the current directory # Get the branch name of the current directory
_lp_git_branch() _lp_git_branch()
{ {
[[ "$LP_ENABLE_GIT" != 1 ]] && return [[ "$LP_ENABLE_GIT" != 1 ]] && return
local gitdir="$(git rev-parse --git-dir 2>/dev/null)" local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
[[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return [[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return
local branch="$(git symbolic-ref HEAD 2>/dev/null)" local branch="$(git symbolic-ref HEAD 2>/dev/null)"
@ -707,7 +721,6 @@ _lp_git_branch_color()
_lp_hg_branch() _lp_hg_branch()
{ {
[[ "$LP_ENABLE_HG" != 1 ]] && return [[ "$LP_ENABLE_HG" != 1 ]] && return
local branch local branch
branch="$(hg branch 2>/dev/null)" branch="$(hg branch 2>/dev/null)"
[[ $? -eq 0 ]] && echo "$branch" [[ $? -eq 0 ]] && echo "$branch"
@ -786,7 +799,6 @@ _lp_svn_branch_color()
_lp_fossil_branch() _lp_fossil_branch()
{ {
[[ "$LP_ENABLE_FOSSIL" != 1 ]] && return [[ "$LP_ENABLE_FOSSIL" != 1 ]] && return
local branch local branch
branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-) branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-)
if [[ -n "$branch" ]] ; then if [[ -n "$branch" ]] ; then
@ -1131,15 +1143,15 @@ _lp_smart_mark()
if [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then if [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
mark="%(!.#.%%)" mark="%(!.#.%%)"
fi fi
if [[ ! -z $(_lp_git_branch) ]] ; then if [[ "$1" == "git" ]]; then
mark=$LP_MARK_GIT mark=$LP_MARK_GIT
elif [[ ! -z $(_lp_hg_branch) ]] ; then elif [[ "$1" == "hg" ]]; then
mark=$LP_MARK_HG mark=$LP_MARK_HG
elif [[ ! -z $(_lp_svn_branch) ]] ; then elif [[ "$1" == "svn" ]]; then
mark=$LP_MARK_SVN mark=$LP_MARK_SVN
elif [[ ! -z $(_lp_fossil_branch) ]] ; then elif [[ "$1" == "fossil" ]]; then
mark=$LP_MARK_FOSSIL mark=$LP_MARK_FOSSIL
elif [[ ! -z $(_lp_bzr_branch) ]] ; then elif [[ "$1" == "bzr" ]]; then
mark=$LP_MARK_BZR mark=$LP_MARK_BZR
fi fi
echo -ne "${COL}${mark}${NO_COL}" echo -ne "${COL}${mark}${NO_COL}"
@ -1208,24 +1220,45 @@ _lp_set_prompt()
# in main prompt: no space # in main prompt: no space
LP_USER=$(_lp_user) LP_USER=$(_lp_user)
# LP_HOST is a global set at load time
LP_PERM=$(_lp_permissions_color)
LP_PWD=$(_lp_shorten_path)
[[ -n "$PROMPT_DIRTRIM" ]] && PROMPT_DIRTRIM=$(_lp_get_dirtrim)
LP_PROXY="${LP_COLOR_PROXY}$(_lp_proxy)${NO_COL}" LP_PROXY="${LP_COLOR_PROXY}$(_lp_proxy)${NO_COL}"
# right of main prompt: space at left # right of main prompt: space at left
LP_VENV=$(_lp_sl "$(_lp_virtualenv)") LP_VENV=$(_lp_sl "$(_lp_virtualenv)")
if [[ "$EUID" -ne "0" ]] || [[ "$LP_ENABLE_VCS_ROOT" = "1" ]] ; then LP_VCS=""
LP_GIT=$(_lp_sl "$(_lp_git_branch_color)") if [[ "$LP_OLD_PWD" != "$PWD" ]]; then
LP_HG=$(_lp_sl "$(_lp_hg_branch_color)") # LP_HOST is a global set at load time
LP_SVN=$(_lp_sl "$(_lp_svn_branch_color)") LP_PERM=$(_lp_permissions_color)
LP_FOSSIL=$(_lp_sl "$(_lp_fossil_branch_color)") LP_PWD=$(_lp_shorten_path)
LP_BZR=$(_lp_sl "$(_lp_bzr_branch_color)") [[ -n "$PROMPT_DIRTRIM" ]] && PROMPT_DIRTRIM=$(_lp_get_dirtrim)
if [[ "$(_lp_are_vcs_disabled)" -eq "0" ]] ; then
LP_VCS="$(_lp_git_branch_color)"
LP_VCS_TYPES="git"
if [[ -z "$LP_VCS" ]]; then
LP_VCS="$(_lp_hg_branch_color)"
LP_VCS_TYPES="hg"
if [[ -z "$LP_VCS" ]]; then
LP_VCS="$(_lp_svn_branch_color)"
LP_VCS_TYPES="svn"
if [[ -z "$LP_VCS" ]]; then
LP_VCS="$(_lp_fossil_branch_color)"
LP_VCS_TYPES="fossil"
if [[ -z "$LP_VCS" ]]; then
LP_VCS="$(_lp_bzr_branch_color)"
LP_VCS_TYPES="bzr"
fi
fi
fi
fi
fi
if [[ -z "$LP_VCS" ]] ; then
LP_VCS_TYPES=""
else
LP_VCS=$(_lp_sl "${LP_VCS}")
fi fi
# end of the prompt line: double spaces # end of the prompt line: double spaces
LP_MARK=$(_lp_sb "$(_lp_smart_mark)") LP_MARK=$(_lp_sb "$(_lp_smart_mark $LP_VCS_TYPES)")
# Different path color if root # Different path color if root
if [[ "$EUID" -ne "0" ]] ; then if [[ "$EUID" -ne "0" ]] ; then
@ -1233,6 +1266,17 @@ _lp_set_prompt()
else else
LP_PWD="${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}" LP_PWD="${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}"
fi 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)");;
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)");;
esac
fi
if [[ -z $LP_PS1 ]] ; then if [[ -z $LP_PS1 ]] ; then
# add title escape time, jobs, load and battery # add title escape time, jobs, load and battery
@ -1246,13 +1290,12 @@ _lp_set_prompt()
# path in foreground color # path in foreground color
PS1="${PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}" PS1="${PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
# add VCS infos # add VCS infos
PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}${LP_FOSSIL}${LP_BZR}" PS1="${PS1}${LP_VCS}"
else else
# path in yellow # path in yellow
PS1="${PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}" PS1="${PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
# do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT) # do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT)
[[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && \ [[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && PS1="${PS1}${LP_VCS}"
PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}${LP_FOSSIL}"
fi fi
# add return code and prompt mark # add return code and prompt mark
PS1="${PS1}${LP_ERR}${LP_MARK}" PS1="${PS1}${LP_ERR}${LP_MARK}"
@ -1272,8 +1315,6 @@ _lp_set_prompt()
else else
PS1=$LP_PS1 PS1=$LP_PS1
fi fi
} }
# Activate the liquid prompt # Activate the liquid prompt

View File

@ -97,4 +97,8 @@ LP_ENABLE_TIME=0
# feature to your specific terminal. # feature to your specific terminal.
LP_ENABLE_TITLE=0 LP_ENABLE_TITLE=0
# Specify a list of complete and colon (":") separated paths in which, all vcs
# will be disabled
LP_DISABLED_VCS_PATH=""
# vim: set et sts=4 sw=4 tw=120 ft=sh: # vim: set et sts=4 sw=4 tw=120 ft=sh: