manual merge

This commit is contained in:
Johann Dreo 2013-01-16 15:47:47 +01:00
commit 819c2c5ae2
5 changed files with 167 additions and 33 deletions

View File

@ -56,14 +56,15 @@ preserving the first two directories;
* the current Python virtual environment, if any; * the current Python virtual environment, if any;
* an up arrow if an HTTP proxy is in use; * an up arrow if an HTTP proxy is in use;
* the name of the current branch if you are in a version control repository * the name of the current branch if you are in a version control repository
(git, mercurial or subversion), in green if everything is up to date, in red if (git, mercurial, subversion or fossil), in green if everything is up
there is changes, in yellow if there is pending commits to push; to date, in red if there is changes, in yellow if there is pending
* the number of added/deleted lines, if changes have been made and the number commits to push;
of pending commits, if any; * the number of added/deleted lines (git) or files (fossil), if
changes have been made and the number of pending commits, if any;
* a star if there is some untracked files in the repository; * a star if there is some untracked files in the repository;
* the error code of the last command, if it has failed in some way; * the error code of the last command, if it has failed in some way;
* a smart mark: ± for git directories, ☿ for mercurial, ‡ for svn, $ for simple * a smart mark: ± for git directories, ☿ for mercurial, ‡ for svn,
user, a red # for root. for fossil, $ for simple user, a red # for root.
* if you ask for, the liquidprompt will be replicated in your terminal window's * if you ask for, the liquidprompt will be replicated in your terminal window's
title (without the colors) title (without the colors)
@ -126,6 +127,7 @@ building:
* `LP_ENABLE_GIT`, if you want to have git informations * `LP_ENABLE_GIT`, if you want to have git informations
* `LP_ENABLE_SVN`, if you want to have subversion informations * `LP_ENABLE_SVN`, if you want to have subversion informations
* `LP_ENABLE_HG`, if you want to have mercurial informations * `LP_ENABLE_HG`, if you want to have mercurial informations
* `LP_ENABLE_FOSSIL`, if you want to have fossil informations
* `LP_ENABLE_VCS_ROOT`, if you want to show VCS informations with root account * `LP_ENABLE_VCS_ROOT`, if you want to show VCS informations with root account
* `LP_ENABLE_TITLE`, if you want to use the prompt as your terminal window's title * `LP_ENABLE_TITLE`, if you want to use the prompt as your terminal window's title
@ -135,6 +137,13 @@ Note also that all the `LP_ENABLE_…` variables override the templates,
i.e. if you use `$LP_BATT` in your template and you set `LP_ENABLE_BATT=0` i.e. if you use `$LP_BATT` in your template and you set `LP_ENABLE_BATT=0`
in your config file, you will not have the battery informations. in your config file, you will not have the battery informations.
If you are using bash and want to use the `PROMPT_DIRTRIM` built-in
functionality to shorten but still have liquidprompt calculating the number of
directories to keep in the path, precise a value for `PROMPT_DIRTRIM` before
sourcing liquidprompt and liquidprompt will override this value with one
fitting the width of your terminal.
## CUSTOMIZING THE PROMPT ## CUSTOMIZING THE PROMPT
### ADD A PS1 PREFIX ### ADD A PS1 PREFIX
@ -164,6 +173,7 @@ Available features:
* `LP_GIT` git * `LP_GIT` git
* `LP_HG` mercurial * `LP_HG` mercurial
* `LP_SVN` subversion * `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
@ -226,7 +236,7 @@ Set to a null string "" if you do not want color.
* `LP_COLOR_UP` repository is up to date / a push have been made * `LP_COLOR_UP` repository is up to date / a push have been made
* `LP_COLOR_COMMITS` some commits have not been pushed * `LP_COLOR_COMMITS` some commits have not been pushed
* `LP_COLOR_CHANGES` there is some changes to commit * `LP_COLOR_CHANGES` there is some changes to commit
* `LP_COLOR_DIFF` number of lines impacted by current changes * `LP_COLOR_DIFF` number of lines or files impacted by current changes
* Battery * Battery
* `LP_COLOR_CHARGING_ABOVE` charging and above threshold * `LP_COLOR_CHARGING_ABOVE` charging and above threshold
* `LP_COLOR_CHARGING_UNDER` charging but under threshold * `LP_COLOR_CHARGING_UNDER` charging but under threshold
@ -244,6 +254,7 @@ Special characters:
* `LP_MARK_HG` (default: "☿") prompt mark in hg repositories * `LP_MARK_HG` (default: "☿") prompt mark in hg repositories
* `LP_MARK_SVN` (default: "‡") prompt mark in svn repositories * `LP_MARK_SVN` (default: "‡") prompt mark in svn repositories
* `LP_MARK_GIT` (default: "±") prompt mark in git repositories * `LP_MARK_GIT` (default: "±") prompt mark in git repositories
* `LP_MARK_FOSSIL` (default: "⌘") prompt mark in fossil repositories
* `LP_MARK_UNTRACKED` (default: "*") if git has untracked files * `LP_MARK_UNTRACKED` (default: "*") if git has untracked files
* `LP_TITLE_OPEN` (default: "\e]0;") escape character opening a window's title * `LP_TITLE_OPEN` (default: "\e]0;") escape character opening a window's title
* `LP_TITLE_CLOSE` (default: "\a") escape character closing a window's title * `LP_TITLE_CLOSE` (default: "\a") escape character closing a window's title
@ -261,6 +272,9 @@ the display of the liquid prompt.
* Subversion repository cannot display commits to be pushed, this is a * Subversion repository cannot display commits to be pushed, this is a
limitation of the Subversion versionning model. limitation of the Subversion versionning model.
* The proxy detection only uses the `$http_proxy` environment variable. * The proxy detection only uses the `$http_proxy` environment variable.
<<<<<<< HEAD
* The window's title escape sequence may not work properly on some terminals * The window's title escape sequence may not work properly on some terminals
(like xterm-256) (like xterm-256)
=======
>>>>>>> 3aedf713f42fcfa91a1eba5cd4b4dbc36a59ee58

View File

@ -34,13 +34,13 @@ 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_PS1="${LP_PS1}${LP_GIT}${LP_HG}${LP_SVN}${LP_FOSSIL}"
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_GIT}${LP_HG}${LP_SVN}" 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

@ -17,6 +17,7 @@ if [[ "$(locale -k LC_CTYPE | sed -n 's/^charmap="\(.*\)"/\1/p')" == *"UTF-8"* ]
LP_MARK_HG="☿" # prompt mark in hg repositories LP_MARK_HG="☿" # prompt mark in hg repositories
LP_MARK_SVN="‡" # prompt mark in svn repositories LP_MARK_SVN="‡" # prompt mark in svn repositories
LP_MARK_GIT="±" # prompt mark in git repositories LP_MARK_GIT="±" # prompt mark in git repositories
LP_MARK_FOSSIL="⌘" # prompt mark in fossil repositories
LP_MARK_UNTRACKED="*" # if git has untracked files LP_MARK_UNTRACKED="*" # if git has untracked files
else else
# If charset is anything else, fallback to ASCII chars # If charset is anything else, fallback to ASCII chars
@ -27,6 +28,7 @@ else
LP_MARK_HG="m" LP_MARK_HG="m"
LP_MARK_SVN="=" LP_MARK_SVN="="
LP_MARK_GIT="+" LP_MARK_GIT="+"
LP_MARK_FOSSIL="f"
LP_MARK_UNTRACKED="*" LP_MARK_UNTRACKED="*"
fi fi

View File

@ -29,7 +29,7 @@
# Joris Dedieu <joris@pontiac3.nfrance.com> # Portability framework, FreeBSD support, bugfixes. # Joris Dedieu <joris@pontiac3.nfrance.com> # Portability framework, FreeBSD support, bugfixes.
# Ludovic Rousseau <ludovic.rousseau@gmail.com> # Lot of bugfixes. # Ludovic Rousseau <ludovic.rousseau@gmail.com> # Lot of bugfixes.
# Yann 'Ze' Richard <ze@nbox.org> # Do not fail on missing commands. # Yann 'Ze' Richard <ze@nbox.org> # Do not fail on missing commands.
# François Schmidts <fschmidts@olfeo.com> # Simpler SSH_IP acquiring method. # François Schmidts <francois.schmidts@gmail.com> # small code fix, _lp_get_dirtrim
# Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use. # Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use.
# Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir. # Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir.
# Luc Didry <luc@fiat-tux.fr> # Zsh port # Luc Didry <luc@fiat-tux.fr> # Zsh port
@ -202,6 +202,7 @@ _lp_source_config()
LP_ENABLE_BATT=${LP_ENABLE_BATT:-1} LP_ENABLE_BATT=${LP_ENABLE_BATT:-1}
LP_ENABLE_GIT=${LP_ENABLE_GIT:-1} LP_ENABLE_GIT=${LP_ENABLE_GIT:-1}
LP_ENABLE_SVN=${LP_ENABLE_SVN:-1} LP_ENABLE_SVN=${LP_ENABLE_SVN:-1}
LP_ENABLE_FOSSIL=${LP_ENABLE_FOSSIL:-1}
LP_ENABLE_HG=${LP_ENABLE_HG:-1} LP_ENABLE_HG=${LP_ENABLE_HG:-1}
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0} LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1} LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
@ -215,6 +216,7 @@ _lp_source_config()
LP_MARK_HG=${LP_MARK_HG:-"☿"} LP_MARK_HG=${LP_MARK_HG:-"☿"}
LP_MARK_SVN=${LP_MARK_SVN:-"‡"} LP_MARK_SVN=${LP_MARK_SVN:-"‡"}
LP_MARK_GIT=${LP_MARK_GIT:-"±"} LP_MARK_GIT=${LP_MARK_GIT:-"±"}
LP_MARK_FOSSIL=${LP_MARK_FOSSIL:-"⌘"}
LP_MARK_UNTRACKED=${LP_MARK_UNTRACKED:-"*"} LP_MARK_UNTRACKED=${LP_MARK_UNTRACKED:-"*"}
LP_COLOR_PATH=${LP_COLOR_PATH:-$BOLD_WHITE} LP_COLOR_PATH=${LP_COLOR_PATH:-$BOLD_WHITE}
@ -287,6 +289,7 @@ unset _lp_source_config
# Disable features if the tool is not installed # Disable features if the tool is not installed
[[ "$LP_ENABLE_GIT" = 1 ]] && { command -v git >/dev/null || LP_ENABLE_GIT=0 ; } [[ "$LP_ENABLE_GIT" = 1 ]] && { command -v git >/dev/null || LP_ENABLE_GIT=0 ; }
[[ "$LP_ENABLE_SVN" = 1 ]] && { command -v svn >/dev/null || LP_ENABLE_SVN=0 ; } [[ "$LP_ENABLE_SVN" = 1 ]] && { command -v svn >/dev/null || LP_ENABLE_SVN=0 ; }
[[ "$LP_ENABLE_FOSSIL" = 1 ]] && { command -v fossil >/dev/null || LP_ENABLE_FOSSIL=0 ; }
[[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; } [[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; }
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; } [[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
@ -345,11 +348,16 @@ _lp_connection()
# The connection is not expected to change from inside the shell, so we # The connection is not expected to change from inside the shell, so we
# build this just once # build this just once
LP_HOST="" LP_HOST=""
if [[ -r /etc/debian_chroot ]] ; then _chroot()
{
if [[ -r /etc/debian_chroot ]] ; then
local debchroot local debchroot
debchroot=$(cat /etc/debian_chroot) debchroot=$(cat /etc/debian_chroot)
LP_HOST="${LP_HOST}(${debchroot})" echo "(${debchroot})"
fi fi
}
LP_HOST="$(_chroot)"
unset _chroot
# If we are connected with a X11 support # If we are connected with a X11 support
if [[ -n "$DISPLAY" ]] ; then if [[ -n "$DISPLAY" ]] ; then
@ -406,8 +414,12 @@ _lp_proxy()
# + keep some left part of the path if asked # + keep some left part of the path if asked
_lp_shorten_path() _lp_shorten_path()
{ {
if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] ; then if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 || -n "$PROMPT_DIRTRIM" ]] ; then
echo "$1" if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
echo "\\w"
else
echo "$(print -P "%~")"
fi
return return
fi fi
# the character that will replace the part of the path that is masked # the character that will replace the part of the path that is masked
@ -418,17 +430,10 @@ _lp_shorten_path()
keep=$LP_PATH_KEEP keep=$LP_PATH_KEEP
fi fi
local len_percent=$2 local p="${PWD/$HOME/~}"
local p
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
p=$(echo "$1" | sed -e "s|$HOME|~|")
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
p=$1
fi
local len="${#p}" local len="${#p}"
local max_len=$((${COLUMNS:-80}*$len_percent/100)) local max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
local mask_len="${#mask}" local mask_len="${#mask}"
local slashes=0 local slashes=0
@ -501,6 +506,31 @@ _lp_shorten_path()
fi fi
} }
# In bash shell, PROMPT_DIRTRIM is the number of directory to keep at the end
# of the displayed path (if "\w" is present in the PS1 var).
# liquidprompt can calculate this number under two condition, path shortening
# must be activated and PROMPT_DIRTRIM must be already set.
_lp_get_dirtrim() {
[[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] && echo 0 && return
local p="${PWD/$HOME/~}"
local len=${#p}
local max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
local PROMPT_DIRTRIM=0
if [[ "$((len))" -gt "$((max_len))" ]]; then
local i
for ((i=$len;i>=0;i--))
do
[[ $(($len-$i)) -gt $max_len ]] && break
[[ "${p:i:1}" == "/" ]] && PROMPT_DIRTRIM=$((PROMPT_DIRTRIM+1))
done
[[ "$((PROMPT_DIRTRIM))" -eq 0 ]] && PROMPT_DIRTRIM=1
fi
echo "$PROMPT_DIRTRIM"
}
# Display a ":" # Display a ":"
# colored in green if user have write permission on the current directory # colored in green if user have write permission on the current directory
# colored in red if it have not. # colored in red if it have not.
@ -739,6 +769,90 @@ _lp_svn_branch_color()
} }
# FOSSIL #
# Get the tag name of the current directory
_lp_fossil_branch()
{
[[ "$LP_ENABLE_FOSSIL" != 1 ]] && return
local branch
branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-)
if [[ -n "$branch" ]] ; then
echo "$branch"
else
if fossil info &>/dev/null ; then
echo "no-tag"
fi
fi
}
# Set a color depending on the branch state:
# - green if the repository is clean
# - red if there is changes to commit
# - yellow if the branch has no tag name
#
# Add the number of impacted files with a
# + when files are ADDED or EDITED
# - when files are DELETED
_lp_fossil_branch_color()
{
[[ "$LP_ENABLE_FOSSIL" != 1 ]] && return
local branch
branch=$(_lp_fossil_branch)
if [[ ! -z "$branch" ]] ; then
local C2E # Modified files (added or edited)
local C2D # Deleted files
local C2A # Extras files
local ret
C2E=$(fossil changes | wc -l)
C2D=$(fossil changes | grep DELETED | wc -l)
let "C2E = $C2E - $C2D"
C2A=$(fossil extras | wc -l)
ret=""
if [[ "$C2E" -gt 0 ]] ; then
ret+="+$C2E"
fi
if [[ "$C2D" -gt 0 ]] ; then
if [[ "$ret" = "" ]] ; then
ret+="-$C2D"
else
ret+="/-$C2D"
fi
fi
if [[ "$C2A" -gt 0 ]] ; then
C2A="$LP_MARK_UNTRACKED"
else
C2A=""
fi
if [[ "$ret" != "" ]] ; then
ret="(${LP_COLOR_DIFF}$ret${NO_COL})"
fi
if [[ "$branch" = "no-tag" ]] ; then
# Warning, your branch has no tag name !
branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}"
else
if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then
# All is up-to-date
branch="${LP_COLOR_UP}$branch$C2A${NO_COL}"
else
# There're some changes to commit
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
fi
fi
echo -ne "$branch"
fi
}
################## ##################
# Battery status # # Battery status #
################## ##################
@ -974,6 +1088,8 @@ _lp_smart_mark()
mark=$LP_MARK_HG mark=$LP_MARK_HG
elif [[ ! -z $(_lp_svn_branch) ]] ; then elif [[ ! -z $(_lp_svn_branch) ]] ; then
mark=$LP_MARK_SVN mark=$LP_MARK_SVN
elif [[ ! -z $(_lp_fossil_branch) ]] ; then
mark=$LP_MARK_FOSSIL
fi fi
echo -ne "${COL}${mark}${NO_COL}" echo -ne "${COL}${mark}${NO_COL}"
} }
@ -1035,11 +1151,8 @@ _lp_set_prompt()
LP_USER=$(_lp_user) LP_USER=$(_lp_user)
# LP_HOST is a global set at load time # LP_HOST is a global set at load time
LP_PERM=$(_lp_permissions_color) LP_PERM=$(_lp_permissions_color)
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then LP_PWD=$(_lp_shorten_path)
LP_PWD=$(_lp_shorten_path "$PWD" $LP_PATH_LENGTH) [[ -n "$PROMPT_DIRTRIM" ]] && PROMPT_DIRTRIM=$(_lp_get_dirtrim)
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
LP_PWD=$(_lp_shorten_path "$(print -P "%~")" $LP_PATH_LENGTH)
fi
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
@ -1048,6 +1161,7 @@ _lp_set_prompt()
LP_GIT=$(_lp_sl "$(_lp_git_branch_color)") LP_GIT=$(_lp_sl "$(_lp_git_branch_color)")
LP_HG=$(_lp_sl "$(_lp_hg_branch_color)") LP_HG=$(_lp_sl "$(_lp_hg_branch_color)")
LP_SVN=$(_lp_sl "$(_lp_svn_branch_color)") LP_SVN=$(_lp_sl "$(_lp_svn_branch_color)")
LP_FOSSIL=$(_lp_sl "$(_lp_fossil_branch_color)")
fi fi
# end of the prompt line: double spaces # end of the prompt line: double spaces
@ -1072,13 +1186,13 @@ _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}" PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}${LP_FOSSIL}"
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_GIT}${LP_HG}${LP_SVN}" 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}"

View File

@ -78,6 +78,10 @@ LP_ENABLE_SVN=1
# Recommended value is 1 # Recommended value is 1
LP_ENABLE_HG=1 LP_ENABLE_HG=1
# Do you want to use the fossil special features ?
# Recommended value is 1
LP_ENABLE_FOSSIL=1
# Show time of the last prompt display # Show time of the last prompt display
# Recommended value is 0 # Recommended value is 0
LP_ENABLE_TIME=0 LP_ENABLE_TIME=0