Separate templates from themes

This add colors to features in the main code, so as to avoid having to specify
them in the template part. LP_PS1 is thus easier to set, with just a list of
features to activate along with basic characters.
This commit is contained in:
nojhan 2012-08-16 12:13:40 +02:00
parent 71c9b6ddb8
commit 170628b676
3 changed files with 19 additions and 17 deletions

View File

@ -131,13 +131,6 @@ Available features:
* `LP_ERR` last error code
* `LP_MARK` prompt mark
Some indicators are not colored by default (mainly those that are _static_), to
put colors on theme you should not forget to add themed colors variable around
them:
LP_PS1="${LP_ERR}" # no color
LP_PS1="${LP_COLOR_ERR}${LP_ERR}${NO_COL}" # colored
For example, if you just want to have a liquidprompt displaying the user and the
host, with a normal full path in blue and only the git support:
@ -205,8 +198,6 @@ Set to a null string "" if you do not want color.
Liquid prompt is distributed under the GNU Affero General Public License
version 3.
* Cannot easily change the colors of features having different state colors
(like the colormap of the load or the colors of the branch name).
* detached sessions only looks for `screen`, a `tmux` support would be nice…
* Does not display the number of commits to be pushed in Mercurial repositories.
* Browsing into very large subversion repositories may dramatically slow down

View File

@ -18,6 +18,9 @@
# LP_ERR last error code
# LP_MARK prompt mark
# Remember that most features come with their corresponding colors,
# see the README.
# add jobs, load and battery
LP_PS1="${LP_BATT}${LP_LOAD}${LP_JOBS}"
# add user, host and permissions colon
@ -27,15 +30,15 @@ LP_PS1="${LP_PS1}[${LP_USER}${LP_HOST}${LP_PERM}"
if [[ "$EUID" -ne "0" ]]
then
# path in foreground color
LP_PS1="${LP_PS1}${LP_COLOR_PATH}${LP_PWD}${NO_COL}]${LP_COLOR_PROXY}${LP_PROXY}${NO_COL}"
LP_PS1="${LP_PS1}${LP_PWD}]${LP_PROXY}"
# add VCS infos
LP_PS1="${LP_PS1}${LP_GIT}${LP_HG}${LP_SVN}"
else
# path in yellow
LP_PS1="${LP_PS1}${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}]${LP_COLOR_PROXY}${LP_PROXY}${NO_COL}"
LP_PS1="${LP_PS1}${LP_PWD}]${LP_PROXY}"
# do not add VCS infos
fi
# add return code and prompt mark
LP_PS1="${LP_PS1}${LP_COLOR_ERR}${LP_ERR}${NO_COL}${LP_MARK}"
LP_PS1="${LP_PS1}${LP_ERR}${LP_MARK}"
# vim: set et sts=4 sw=4 tw=120 ft=sh:

View File

@ -195,6 +195,7 @@ LP_PROXY_MARK=${LP_PROXY_MARK:-"↥"}
LP_GIT_MARK=${LP_GIT_MARK:-"±"}
LP_MERCURIAL_MARK=${LP_MERCURIAL_MARK:-"☿"}
LP_SUBVERSION_MARK=${LP_SUBVERSION_MARK:-"‡"}
LP_ENABLE_GIT=${LP_ENABLE_GIT:-1}
LP_ENABLE_SVN=${LP_ENABLE_SVN:-1}
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
@ -909,7 +910,7 @@ _lp_sb()
_lp_set_bash_prompt()
{
# as this get the last returned code, it should be called first
LP_ERR=$(_lp_sl "$(_lp_return_value $?)")
LP_ERR="${LP_COLOR_ERR}$(_lp_sl $(_lp_return_value $?))${NO_COL}"
# execute the old prompt
$LP_OLD_PROMPT_COMMAND
@ -924,7 +925,7 @@ _lp_set_bash_prompt()
# LP_HOST is a global set at load time
LP_PERM=$(_lp_permissions_color)
LP_PWD=$(_lp_shorten_path "$PWD" $LP_PATH_LENGTH)
LP_PROXY=$(_lp_proxy)
LP_PROXY="${LP_COLOR_PROXY}$(_lp_proxy)${NO_COL}"
# right of main prompt: space at left
LP_GIT=$(_lp_sl "$(_lp_git_branch_color)")
@ -934,6 +935,13 @@ _lp_set_bash_prompt()
# end of the prompt line: double spaces
LP_MARK=$(_lp_sb "$(_lp_smart_mark)")
# Different path color if root
if [[ "$EUID" -ne "0" ]] ; then
LP_PWD="${LP_COLOR_PATH}${LP_PWD}${NO_COL}"
else
LP_PWD="${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}"
fi
if [[ -z $LP_PS1 ]] ; then
# add jobs, load and battery
PS1="${LP_BATT}${LP_LOAD}${LP_JOBS}"
@ -944,16 +952,16 @@ _lp_set_bash_prompt()
if [[ "$EUID" -ne "0" ]]
then
# path in foreground color
PS1="${PS1}${LP_COLOR_PATH}${LP_PWD}${NO_COL}]${LP_COLOR_PROXY}${LP_PROXY}${NO_COL}"
PS1="${PS1}${LP_PWD}]${LP_PROXY}"
# add VCS infos
PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}"
else
# path in yellow
PS1="${PS1}${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}]${LP_COLOR_PROXY}${LP_PROXY}${NO_COL}"
PS1="${PS1}${LP_PWD}]${LP_PROXY}"
# do not add VCS infos
fi
# add return code and prompt mark
PS1="${PS1}${LP_COLOR_ERR}${LP_ERR}${NO_COL}${LP_MARK}"
PS1="${PS1}${LP_ERR}${LP_MARK}"
# Glue the bash prompt always go to the first column.
# Avoid glitches after interrupting a command with Ctrl-C