Merge branch 'develop'
Merge changes from the develop branch: - many fixes, in particular for MacOS X (battery) - many speed improvments (Mercurial, Subversion) - many reliability improvments (SHORTEN_PATH feature) Ready for a release.
This commit is contained in:
commit
0921e720c2
@ -10,7 +10,7 @@ The main branch for development is `develop`. This is on top of this branch
|
||||
that you must write your patches.
|
||||
|
||||
Any pull request built on top of `master` instead of `develop`
|
||||
is additionnal merge work for maintainers, and you want to avoid this if you
|
||||
is additional merge work for maintainers, and you want to avoid this if you
|
||||
aim for quick integration of your work.
|
||||
|
||||
If you wrote your patch on the wrong branch the maintainers may choose to close
|
||||
@ -41,7 +41,7 @@ How to do the right thing?
|
||||
|
||||
# Check that your local repo is up to date
|
||||
$ git fetch
|
||||
# Rebase your work on the lastest state of `develop`
|
||||
# Rebase your work on the latest state of `develop`
|
||||
$ git rebase upstream/develop
|
||||
|
||||
# Push
|
||||
|
@ -92,7 +92,7 @@ git clone https://github.com/nojhan/liquidprompt.git
|
||||
source liquidprompt/liquidprompt
|
||||
```
|
||||
|
||||
To use it everytime you start a shell add the following line to your
|
||||
To use it every time you start a shell add the following line to your
|
||||
`.bashrc` (if you use bash) or `.zshrc` (if you use zsh):
|
||||
|
||||
`source ~/liquidprompt/liquidprompt`
|
||||
@ -284,6 +284,7 @@ Set to a null string "" if you do not want color.
|
||||
* Prompt mark
|
||||
* `LP_COLOR_MARK` as user
|
||||
* `LP_COLOR_MARK_ROOT` as root
|
||||
* `LP_MARK_PREFIX="\n"` put the prompt on the second line
|
||||
* Current user
|
||||
* `LP_COLOR_USER_LOGGED` user who logged in
|
||||
* `LP_COLOR_USER_ALT` user but not the one who logged in
|
||||
@ -342,11 +343,11 @@ version 3.
|
||||
* Browsing into very large subversion repositories may dramatically slow down
|
||||
the display of the liquid prompt (use `LP_DISABLED_VCS_PATH` to avoid that).
|
||||
* Subversion repository cannot display commits to be pushed, this is a
|
||||
limitation of the Subversion versionning model.
|
||||
limitation of the Subversion versioning model.
|
||||
* The proxy detection only uses the `$http_proxy` environment variable.
|
||||
* The window's title escape sequence may not work properly on some terminals
|
||||
(like xterm-256)
|
||||
* The analog clock necessitate a unicode-aware terminal and a at least one
|
||||
* The analog clock necessitate a Unicode-aware terminal and a at least one
|
||||
sufficiently complete font on your system.
|
||||
The [Symbola](http://users.teilar.gr/~g1951d/) font, designed by Georges Douros,
|
||||
is known to work well.
|
||||
|
558
liquidprompt
558
liquidprompt
@ -32,7 +32,7 @@
|
||||
# David Loureiro <david.loureiro@sysfera.com> # Small portability fix
|
||||
# Étienne Deparis <etienne@depar.is> # Fossil support
|
||||
# Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir.
|
||||
# François Schmidts <francois.schmidts@gmail.com> # Small code fix, _lp_get_dirtrim
|
||||
# François Schmidts <francois.schmidts@gmail.com> # Initial PROMPT_DIRTRIM support
|
||||
# Frédéric Lepied <flepied@gmail.com> # Python virtual env
|
||||
# Jonas Bengtsson <jonas.b@gmail.com> # Git remotes fix
|
||||
# Joris Dedieu <joris@pontiac3.nfrance.com> # Portability framework, FreeBSD support, bugfixes.
|
||||
@ -44,13 +44,17 @@
|
||||
# nojhan <nojhan@gmail.com> # Original author.
|
||||
# Olivier Mengué <dolmen@cpan.org> # Major optimizations, refactorings everywhere; current maintainer
|
||||
# Poil <poil@quake.fr> # Speed improvements
|
||||
# Rolf Morel <rolfmorel@gmail.com> # "Shorten path" refactoring and fixes
|
||||
# Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use.
|
||||
# Yann 'Ze' Richard <ze@nbox.org> # Do not fail on missing commands.
|
||||
|
||||
# See the README.md file for a summary of features.
|
||||
|
||||
# Issue #161: do not load if not an interactive shell
|
||||
test -z "$TERM" -o "x$TERM" = dumb && return
|
||||
|
||||
# Check for recent enough version of bash.
|
||||
if test -n "$BASH_VERSION" -a -n "$PS1" -a -n "$TERM" ; then
|
||||
if test -n "$BASH_VERSION" -a -n "$PS1" ; then
|
||||
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
|
||||
if [[ $bmajor -lt 3 ]] || [[ $bmajor -eq 3 && $bminor -lt 2 ]]; then
|
||||
unset bash bmajor bminor
|
||||
@ -67,6 +71,7 @@ if test -n "$BASH_VERSION" -a -n "$PS1" -a -n "$TERM" ; then
|
||||
_LP_TIME_SYMBOL="\t"
|
||||
_LP_MARK_SYMBOL='\$'
|
||||
_LP_FIRST_INDEX=0
|
||||
_LP_PWD_SYMBOL="\\w"
|
||||
elif test -n "$ZSH_VERSION" ; then
|
||||
_LP_SHELL_bash=false
|
||||
_LP_SHELL_zsh=true
|
||||
@ -77,6 +82,7 @@ elif test -n "$ZSH_VERSION" ; then
|
||||
_LP_TIME_SYMBOL="%*"
|
||||
_LP_MARK_SYMBOL='%(!.#.%%)'
|
||||
_LP_FIRST_INDEX=1
|
||||
_LP_PWD_SYMBOL="%~"
|
||||
else
|
||||
echo "liquidprompt: shell not supported" >&2
|
||||
return
|
||||
@ -104,6 +110,11 @@ case "$LP_OS" in
|
||||
SunOS) _lp_CPUNUM=$( kstat -m cpu_info | grep -c "module: cpu_info" ) ;;
|
||||
esac
|
||||
|
||||
# Extended regexp patterns for sed
|
||||
# GNU/BSD sed
|
||||
_LP_SED_EXTENDED=r
|
||||
[[ "$LP_OS" = Darwin ]] && _LP_SED_EXTENDED=E
|
||||
|
||||
|
||||
# get current load
|
||||
case "$LP_OS" in
|
||||
@ -114,7 +125,7 @@ case "$LP_OS" in
|
||||
echo "$load"
|
||||
}
|
||||
;;
|
||||
FreeBSD)
|
||||
FreeBSD|Darwin|OpenBSD)
|
||||
_lp_cpu_load () {
|
||||
local bol load eol
|
||||
# If you have problems with syntax coloring due to the following
|
||||
@ -124,27 +135,14 @@ case "$LP_OS" in
|
||||
echo "$load"
|
||||
}
|
||||
;;
|
||||
Darwin)
|
||||
_lp_cpu_load () {
|
||||
local bol load eol
|
||||
read bol load eol <<<$( LANG=C sysctl -n vm.loadavg )
|
||||
echo "$load"
|
||||
}
|
||||
LP_DWIN_KERNEL_REL_VER=$(uname -r | cut -d . -f 1)
|
||||
;;
|
||||
OpenBSD)
|
||||
_lp_cpu_load() {
|
||||
local bol load eol
|
||||
read one two three <<< `sysctl -n vm.loadavg`
|
||||
echo "$load"
|
||||
}
|
||||
;;
|
||||
SunOS)
|
||||
_lp_cpu_load () {
|
||||
LANG=C uptime | awk '{print substr($10,0,length($10))}'
|
||||
}
|
||||
esac
|
||||
|
||||
# Reset so all PWD dependent variables are computed after loading
|
||||
unset LP_OLD_PWD
|
||||
|
||||
#################
|
||||
# CONFIGURATION #
|
||||
@ -223,6 +221,7 @@ _lp_source_config()
|
||||
LP_RUNTIME_THRESHOLD=${LP_RUNTIME_THRESHOLD:-2}
|
||||
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
|
||||
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
|
||||
LP_PATH_DEFAULT="${LP_PATH_DEFAULT:-$_LP_PWD_SYMBOL}"
|
||||
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
|
||||
LP_USER_ALWAYS=${LP_USER_ALWAYS:-1}
|
||||
LP_PERCENTS_ALWAYS=${LP_PERCENTS_ALWAYS:-1}
|
||||
@ -247,37 +246,36 @@ _lp_source_config()
|
||||
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
|
||||
LP_ENABLE_BZR=${LP_ENABLE_BZR:-1}
|
||||
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
|
||||
if [[ "$_LP_SHELL_bash" == true ]]
|
||||
then
|
||||
if $_LP_SHELL_bash; then
|
||||
LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-1}
|
||||
else
|
||||
[[ "$LP_ENABLE_RUNTIME" == 1 ]] && echo Unfortunately, runtime printing for zsh is not yet supported. Turn LP_ENABLE_RUNTIME off in your config to hide this message.
|
||||
LP_ENABLE_RUNTIME=0
|
||||
LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-0}
|
||||
fi
|
||||
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
|
||||
LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
|
||||
LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0}
|
||||
LP_ENABLE_SCREEN_TITLE=${LP_ENABLE_SCREEN_TITLE:-0}
|
||||
LP_ENABLE_SSH_COLORS=${LP_ENABLE_SSH_COLORS:-0}
|
||||
LP_DISABLED_VCS_PATH=${LP_DISABLED_VCS_PATH:-""}
|
||||
# LP_DISABLED_VCS_PATH="${LP_DISABLED_VCS_PATH}"
|
||||
|
||||
LP_MARK_DEFAULT=${LP_MARK_DEFAULT:-""}
|
||||
LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"}
|
||||
LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"}
|
||||
LP_MARK_LOAD=${LP_MARK_LOAD:-"⌂"}
|
||||
LP_MARK_TEMP=${LP_MARK_TEMP:-"θ"}
|
||||
LP_MARK_PROXY=${LP_MARK_PROXY:-"↥"}
|
||||
LP_MARK_HG=${LP_MARK_HG:-"☿"}
|
||||
LP_MARK_SVN=${LP_MARK_SVN:-"‡"}
|
||||
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:-"["}
|
||||
LP_MARK_BRACKET_CLOSE=${LP_MARK_BRACKET_CLOSE:-"]"}
|
||||
LP_MARK_SHORTEN_PATH=${LP_MARK_SHORTEN_PATH:-" … "}
|
||||
# LP_MARK_DEFAULT="$LP_MARK_DEFAULT"
|
||||
LP_MARK_BATTERY="${LP_MARK_BATTERY:-"⌁"}"
|
||||
LP_MARK_ADAPTER="${LP_MARK_ADAPTER:-"⏚"}"
|
||||
LP_MARK_LOAD="${LP_MARK_LOAD:-"⌂"}"
|
||||
LP_MARK_TEMP="${LP_MARK_TEMP:-"θ"}"
|
||||
LP_MARK_PROXY="${LP_MARK_PROXY:-"↥"}"
|
||||
LP_MARK_HG="${LP_MARK_HG:-"☿"}"
|
||||
LP_MARK_SVN="${LP_MARK_SVN:-"‡"}"
|
||||
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:-"["}"
|
||||
LP_MARK_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE:-"]"}"
|
||||
LP_MARK_SHORTEN_PATH="${LP_MARK_SHORTEN_PATH:-" … "}"
|
||||
# LP_MARK_PREFIX="$LP_MARK_PREFIX"
|
||||
|
||||
LP_COLOR_PATH=${LP_COLOR_PATH:-$BOLD}
|
||||
LP_COLOR_PATH_ROOT=${LP_COLOR_PATH_ROOT:-$BOLD_YELLOW}
|
||||
@ -362,15 +360,42 @@ case "$LP_OS" in
|
||||
*) [[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; };;
|
||||
esac
|
||||
|
||||
if [[ "$LP_ENABLE_RUNTIME" == 1 ]] && ! $_LP_SHELL_bash; then
|
||||
echo Unfortunately, runtime printing for zsh is not yet supported. Turn LP_ENABLE_RUNTIME off in your config to hide this message.
|
||||
LP_ENABLE_RUNTIME=0
|
||||
fi
|
||||
|
||||
# If we are running in a terminal multiplexer, brackets are colored
|
||||
if [[ "$TERM" == screen* ]]; then
|
||||
LP_BRACKET_OPEN="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_OPEN}${NO_COL}"
|
||||
LP_BRACKET_CLOSE="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_CLOSE}${NO_COL}"
|
||||
(( LP_ENABLE_TITLE = LP_ENABLE_TITLE && LP_ENABLE_SCREEN_TITLE ))
|
||||
LP_TITLE_OPEN="$LP_SCREEN_TITLE_OPEN"
|
||||
LP_TITLE_CLOSE="$LP_SCREEN_TITLE_CLOSE"
|
||||
else
|
||||
LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}"
|
||||
LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}"
|
||||
fi
|
||||
|
||||
[[ "_$TERM" == _linux* ]] && LP_ENABLE_TITLE=0
|
||||
|
||||
# update_terminal_cwd is a shell function available on MacOS X Lion that
|
||||
# will update an icon of the directory displayed in the title of the terminal
|
||||
# window.
|
||||
# See http://hints.macworld.com/article.php?story=20110722211753852
|
||||
if [[ "$TERM_PROGRAM" == Apple_Terminal ]] && command -v update_terminal_cwd >/dev/null; then
|
||||
_LP_TERM_UPDATE_DIR=update_terminal_cwd
|
||||
# Remove "update_terminal_cwd; " that has been add by Apple in /et/bashrc.
|
||||
# See issue #196
|
||||
PROMPT_COMMAND="${PROMPT_COMMAND//update_terminal_cwd; /}"
|
||||
else
|
||||
_LP_TERM_UPDATE_DIR=:
|
||||
fi
|
||||
|
||||
# Default value for LP_PERM when LP_ENABLE_PERM is 0
|
||||
LP_PERM=: # without color
|
||||
|
||||
|
||||
# Escape the given strings
|
||||
# Must be used for all strings that may comes from remote sources,
|
||||
# like VCS branch names
|
||||
@ -494,161 +519,104 @@ esac
|
||||
unset _lp_connection
|
||||
|
||||
|
||||
# BASH/ZSH function that shortens
|
||||
# a very long path for display by removing
|
||||
# the left most parts and replacing them
|
||||
# with a leading ...
|
||||
#
|
||||
# the first argument is the path
|
||||
#
|
||||
# the second argument is the maximum allowed
|
||||
# length including the '/'s and ...
|
||||
# http://hbfs.wordpress.com/2009/09/01/short-pwd-in-bash-prompts/
|
||||
#
|
||||
# + keep some left part of the path if asked
|
||||
# Shorten the path of the current working directory
|
||||
# * Show only the current directory
|
||||
# * Show as much of the cwd path as possible, if shortened display a
|
||||
# leading mark, such as ellipses, to indicate that part is missing
|
||||
# * show at least LP_PATH_KEEP leading dirs and current directory
|
||||
_lp_shorten_path()
|
||||
{
|
||||
if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 || -n "$PROMPT_DIRTRIM" ]] ; then
|
||||
|
||||
if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] ; then
|
||||
LP_PWD="$LP_PATH_DEFAULT"
|
||||
if $_LP_SHELL_bash; then
|
||||
echo "\\w"
|
||||
else
|
||||
print -P '%~'
|
||||
[[ -n "$PROMPT_DIRTRIM" ]] && _lp_set_dirtrim
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
local ret=""
|
||||
|
||||
local p="${PWD/#$HOME/~}"
|
||||
local -i len=${#p}
|
||||
local -i max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
|
||||
local mask="${LP_MARK_SHORTEN_PATH}"
|
||||
local -i max_len=$(( ${COLUMNS:-80} * $LP_PATH_LENGTH / 100 ))
|
||||
|
||||
if [[ ${LP_PATH_KEEP} == -1 ]]; then
|
||||
# only show the current directory, excluding any parent dirs
|
||||
ret="${p##*/}" # discard everything upto and including the last slash
|
||||
[[ "${ret}" == "" ]] && ret="/" # if in root directory
|
||||
elif (( ${#p} <= ${max_len} )); then
|
||||
ret="${p}"
|
||||
elif [[ ${LP_PATH_KEEP} == 0 ]]; then
|
||||
# len is over max len, show as much of the tail as is allowed
|
||||
ret="${p##*/}" # show at least complete current directory
|
||||
p="${p:0:${#p} - ${#ret}}"
|
||||
ret="${mask}${p:${#p} - (${max_len} - ${#ret} - ${#mask})}${ret}"
|
||||
else
|
||||
# len is over max len, show at least LP_PATH_KEEP leading dirs and
|
||||
# current directory
|
||||
local tmp=${p//\//}
|
||||
local -i delims=$(( ${#p} - ${#tmp} ))
|
||||
|
||||
for (( dir=0; dir < ${LP_PATH_KEEP}; dir++ )); do
|
||||
(( ${dir} == ${delims} )) && break
|
||||
|
||||
local left="${p#*/}"
|
||||
local name="${p:0:${#p} - ${#left}}"
|
||||
p="${left}"
|
||||
ret="${ret}${name%/}/"
|
||||
done
|
||||
|
||||
if (( ${delims} <= ${LP_PATH_KEEP} )); then
|
||||
# no dirs between LP_PATH_KEEP leading dirs and current dir
|
||||
ret="${ret}${p##*/}"
|
||||
else
|
||||
local base="${p##*/}"
|
||||
|
||||
p="${p:0:${#p} - ${#base}}"
|
||||
|
||||
[[ ${ret} != "/" ]] && ret="${ret%/}" # strip trailing slash
|
||||
|
||||
local -i len_left=$(( ${max_len} - ${#ret} - ${#base} - ${#mask} ))
|
||||
|
||||
ret="${ret}${mask}${p:${#p} - ${len_left}}${base}"
|
||||
fi
|
||||
fi
|
||||
# Escape special chars
|
||||
if $_LP_SHELL_bash; then
|
||||
if (( len > max_len ))
|
||||
then
|
||||
# index of the directory to keep from the root
|
||||
# (starts at 0 whith bash, 1 with zsh)
|
||||
local -i keep=LP_PATH_KEEP-1
|
||||
# the character that will replace the part of the path that is
|
||||
# masked
|
||||
local mask="$LP_MARK_SHORTEN_PATH"
|
||||
local -i mask_len=${#mask}
|
||||
# finds all the '/' in
|
||||
# the path and stores their
|
||||
# positions
|
||||
#
|
||||
local pos=()
|
||||
local -i slashes=0
|
||||
for ((i=0;i<len;i++))
|
||||
do
|
||||
if [[ "${p:i:1}" == / ]]
|
||||
then
|
||||
pos=(${pos[@]} $i)
|
||||
let slashes++
|
||||
fi
|
||||
done
|
||||
pos=(${pos[@]} $len)
|
||||
|
||||
# we have the '/'s, let's find the
|
||||
# left-most that doesn't break the
|
||||
# length limit
|
||||
#
|
||||
local -i i=keep
|
||||
if (( keep > slashes )) ; then
|
||||
i=slashes
|
||||
fi
|
||||
while (( len-pos[i] > max_len-mask_len ))
|
||||
do
|
||||
let i++
|
||||
done
|
||||
|
||||
# let us check if it's OK to
|
||||
# print the whole thing
|
||||
#
|
||||
if (( pos[i] == 0 ))
|
||||
then
|
||||
# the path is shorter than
|
||||
# the maximum allowed length,
|
||||
# so no need for '…'
|
||||
#
|
||||
echo "$p"
|
||||
|
||||
elif (( pos[i] == len ))
|
||||
then
|
||||
# constraints are broken because
|
||||
# the maximum allowed size is smaller
|
||||
# than the last part of the path, plus
|
||||
# ' … '
|
||||
#
|
||||
echo "${p:0:pos[keep]+1}${mask}${p:len-max_len+mask_len}"
|
||||
else
|
||||
# constraints are satisfied, at least
|
||||
# some parts of the path, plus ' … ', are
|
||||
# shorter than the maximum allowed size
|
||||
#
|
||||
echo "${p:0:pos[keep]+1}${mask}${p:pos[i]}"
|
||||
fi
|
||||
else
|
||||
echo "$p"
|
||||
fi
|
||||
LP_PWD="${ret//\\/\\\\}"
|
||||
else # zsh
|
||||
unset p
|
||||
if (( len > max_len )); then
|
||||
print -P "%-${LP_PATH_KEEP}~%${max_len}<${LP_MARK_SHORTEN_PATH}<%~%<<"
|
||||
else
|
||||
print -P '%~'
|
||||
fi
|
||||
LP_PWD="${ret//\%/%%}"
|
||||
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
|
||||
|
||||
# must be disabled and PROMPT_DIRTRIM must be already set.
|
||||
_lp_set_dirtrim() {
|
||||
local p="${PWD/$HOME/~}"
|
||||
local len=${#p}
|
||||
local max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
|
||||
local PROMPT_DIRTRIM=0
|
||||
local -i max_len=${COLUMNS:-80}*$LP_PATH_LENGTH/100
|
||||
local -i dt=0
|
||||
|
||||
if [[ "$((len))" -gt "$((max_len))" ]]; then
|
||||
local i
|
||||
|
||||
for ((i=$len;i>=0;i--))
|
||||
if (( ${#p} > max_len )); then
|
||||
local q="/${p##*/}"
|
||||
local show="$q"
|
||||
# +3 because of the ellipsis: "..."
|
||||
while (( ${#show}+3 < max_len ))
|
||||
do
|
||||
[[ $(($len-$i)) -gt $max_len ]] && break
|
||||
[[ "${p:i:1}" == "/" ]] && PROMPT_DIRTRIM=$((PROMPT_DIRTRIM+1))
|
||||
(( dt++ ))
|
||||
p="${p%$q}"
|
||||
q="/${p##*/}"
|
||||
show="$q$show"
|
||||
done
|
||||
[[ "$((PROMPT_DIRTRIM))" -eq 0 ]] && PROMPT_DIRTRIM=1
|
||||
(( dt == 0 )) && dt=1
|
||||
fi
|
||||
unset p
|
||||
echo "$PROMPT_DIRTRIM"
|
||||
PROMPT_DIRTRIM=$dt
|
||||
# For debugging
|
||||
# echo PROMPT_DIRTRIM=$PROMPT_DIRTRIM >&2
|
||||
}
|
||||
|
||||
# Display a ":"
|
||||
# colored in green if user have write permission on the current directory
|
||||
# colored in red if it have not.
|
||||
_lp_permissions_color()
|
||||
{
|
||||
if [[ "$LP_ENABLE_PERM" != 1 ]]; then
|
||||
echo : # without color
|
||||
else
|
||||
if [[ -w "${PWD}" ]]; then
|
||||
echo "${LP_COLOR_WRITE}:${NO_COL}"
|
||||
else
|
||||
echo "${LP_COLOR_NOWRITE}:${NO_COL}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Display the current Python virtual environnement, if available.
|
||||
_lp_virtualenv()
|
||||
{
|
||||
[[ "$LP_ENABLE_VIRTUALENV" != 1 ]] && return
|
||||
if [[ -n "$VIRTUAL_ENV" ]]; then
|
||||
echo "[${LP_COLOR_VIRTUALENV}$(basename $VIRTUAL_ENV)${NO_COL}]"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
################
|
||||
@ -665,7 +633,7 @@ _lp_jobcount_color()
|
||||
|
||||
local running=$(( $(jobs -r | wc -l) ))
|
||||
local stopped=$(( $(jobs -s | wc -l) ))
|
||||
local n_screen=$(screen -ls 2> /dev/null | grep -c Detach)
|
||||
local n_screen=$(screen -ls 2> /dev/null | grep -c '([Dd]etach[^)]*)$')
|
||||
local n_tmux=$(tmux list-sessions 2> /dev/null | grep -cv attached)
|
||||
local detached=$(( $n_screen + $n_tmux ))
|
||||
local m_detached="d"
|
||||
@ -768,16 +736,32 @@ _lp_git_branch_color()
|
||||
fi
|
||||
fi
|
||||
|
||||
local shortstat
|
||||
local ret
|
||||
local shortstat # only to check for uncommitted changes
|
||||
shortstat="$(LC_ALL=C \git diff --shortstat HEAD 2>/dev/null)"
|
||||
|
||||
if [[ -n "$shortstat" ]] ; then
|
||||
local u_stat # shorstat of *unstaged* changes
|
||||
u_stat="$(LC_ALL=C \git diff --shortstat 2>/dev/null)"
|
||||
u_stat=${u_stat/*changed, /} # removing "n file(s) changed"
|
||||
|
||||
local i_lines # inserted lines
|
||||
if [[ "$u_stat" = *insertion* ]] ; then
|
||||
i_lines=${u_stat/ inser*}
|
||||
else
|
||||
i_lines=0
|
||||
fi
|
||||
|
||||
local d_lines # deleted lines
|
||||
if [[ "$u_stat" = *deletion* ]] ; then
|
||||
d_lines=${u_stat/*\(+\), }
|
||||
d_lines=${d_lines/ del*/}
|
||||
else
|
||||
d_lines=0
|
||||
fi
|
||||
|
||||
local has_lines
|
||||
#has_lines=$(\git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
|
||||
has_lines=${shortstat/*changed, /}
|
||||
has_lines=${has_lines/ inser*, /\/-}
|
||||
has_lines=${has_lines/ del*/}
|
||||
[[ "$shortstat" = *insertion* ]] && has_lines="+${has_lines/ inser*/}" || has_lines="-$has_lines"
|
||||
has_lines="+$i_lines/-$d_lines"
|
||||
|
||||
if [[ "$has_commit" -gt "0" ]] ; then
|
||||
# Changes to commit and commits to push
|
||||
@ -801,19 +785,14 @@ _lp_git_branch_color()
|
||||
# the given name. Used to avoid invoking 'hg' and 'bzr'.
|
||||
_lp_upwards_find()
|
||||
{
|
||||
while [[ "$PWD" != "/" ]] ; do
|
||||
|
||||
# See if it's in the current directory.
|
||||
local found=$(find "$PWD"/ -maxdepth 1 -name "$@" 2> /dev/null)
|
||||
|
||||
# If it is, then echo the path (or anything), and return.
|
||||
if [[ -n found ]] ; then
|
||||
echo $found
|
||||
return
|
||||
fi
|
||||
|
||||
cd ..
|
||||
local dir
|
||||
dir="$PWD"
|
||||
while [[ -n "$dir" ]]
|
||||
do
|
||||
[[ -d "$dir/$1" ]] && return 0
|
||||
dir="${dir%/*}"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# MERCURIAL #
|
||||
@ -822,15 +801,15 @@ _lp_upwards_find()
|
||||
_lp_hg_branch()
|
||||
{
|
||||
[[ "$LP_ENABLE_HG" != 1 ]] && return
|
||||
|
||||
|
||||
# First do a simple search to avoid having to invoke hg -- at least on my
|
||||
# machine, the python startup causes a noticeable hitch when changing
|
||||
# directories.
|
||||
[[ -z "$(_lp_upwards_find '.hg')" ]] && return
|
||||
_lp_upwards_find .hg || return
|
||||
|
||||
# We found an .hg folder, so we need to invoke hg and see if we're actually
|
||||
# in a repository.
|
||||
|
||||
|
||||
local branch
|
||||
branch="$(hg branch 2>/dev/null)"
|
||||
|
||||
@ -967,45 +946,45 @@ _lp_fossil_branch_color()
|
||||
local C2E # Modified files (added or edited)
|
||||
local C2D # Deleted files
|
||||
local C2A # Extras files
|
||||
local C2AA # Added files
|
||||
local PLUSLINE # Added lines
|
||||
local MINUSLINE # Deleted lines
|
||||
local C2AA # Added files
|
||||
local PLUSLINE # Added lines
|
||||
local MINUSLINE # Deleted lines
|
||||
local ret
|
||||
C2E=$(fossil changes | wc -l)
|
||||
C2A=$(fossil extras | wc -l)
|
||||
PLUSLINE=$(fossil diff | egrep '^\+[^+].+$' | wc -l)
|
||||
MINUSLINE=$(fossil diff | egrep '^-[^-].+$' | wc -l)
|
||||
PLUSLINE=$(fossil diff | egrep '^\+[^+].+$' | wc -l)
|
||||
MINUSLINE=$(fossil diff | egrep '^-[^-].+$' | wc -l)
|
||||
ret=""
|
||||
|
||||
C2AA=`fossil changes | grep ADDED | wc -l`
|
||||
if [[ $C2AA -gt 0 ]] ; then
|
||||
# We count the line "à la" git
|
||||
local ADDFILE
|
||||
local FILE
|
||||
ADDFILE=`fossil changes | grep ADDED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2`
|
||||
for FILE in $ADDFILE ; do
|
||||
PLULI=$(wc -l $FILE | cut -d" " -f1)
|
||||
let PLUSLINE=$PLUSLINE+$PLULI
|
||||
done
|
||||
fi
|
||||
C2AA=`fossil changes | grep ADDED | wc -l`
|
||||
if [[ $C2AA -gt 0 ]] ; then
|
||||
# We count the line "à la" git
|
||||
local ADDFILE
|
||||
local FILE
|
||||
ADDFILE=`fossil changes | grep ADDED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2`
|
||||
for FILE in $ADDFILE ; do
|
||||
PLULI=$(wc -l $FILE | cut -d" " -f1)
|
||||
let PLUSLINE=$PLUSLINE+$PLULI
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $PLUSLINE -gt 0 ]] ; then
|
||||
ret+="+$PLUSLINE"
|
||||
fi
|
||||
ret+="+$PLUSLINE"
|
||||
fi
|
||||
|
||||
C2D=`fossil changes | grep DELETED | wc -l`
|
||||
if [[ $C2D -gt 0 ]] ; then
|
||||
# We count the line "à la" git
|
||||
local DELFILE
|
||||
local FILE
|
||||
DELFILE=`fossil changes | grep DELETED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2`
|
||||
for FILE in $DELFILE ; do
|
||||
MINLI=$(wc -l $FILE | cut -d" " -f1)
|
||||
let MINUSLINE=$MINUSLINE+$MINLI
|
||||
done
|
||||
fi
|
||||
C2D=`fossil changes | grep DELETED | wc -l`
|
||||
if [[ $C2D -gt 0 ]] ; then
|
||||
# We count the line "à la" git
|
||||
local DELFILE
|
||||
local FILE
|
||||
DELFILE=`fossil changes | grep DELETED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2`
|
||||
for FILE in $DELFILE ; do
|
||||
MINLI=$(wc -l $FILE | cut -d" " -f1)
|
||||
let MINUSLINE=$MINUSLINE+$MINLI
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ $MINUSLINE -gt 0 ]] ; then
|
||||
if [[ $MINUSLINE -gt 0 ]] ; then
|
||||
if [[ "$ret" = "" ]] ; then
|
||||
ret+="-$MINUSLINE"
|
||||
else
|
||||
@ -1054,7 +1033,7 @@ _lp_bzr_branch()
|
||||
# First do a simple search to avoid having to invoke bzr -- at least on my
|
||||
# machine, the python startup causes a noticeable hitch when changing
|
||||
# directories.
|
||||
[[ -z $(_lp_upwards_find '.bzr') ]] && return
|
||||
_lp_upwards_find .bzr || return
|
||||
|
||||
# We found an .bzr folder, so we need to invoke bzr and see if we're
|
||||
# actually in a repository.
|
||||
@ -1079,7 +1058,7 @@ _lp_bzr_branch_color()
|
||||
# First do a simple search to avoid having to invoke bzr -- at least on my
|
||||
# machine, the python startup causes a noticeable hitch when changing
|
||||
# directories.
|
||||
[[ -z $(_lp_upwards_find '.bzr') ]] && return
|
||||
_lp_upwards_find .bzr || return
|
||||
|
||||
# We found an .bzr folder, so we need to invoke bzr and see if we're
|
||||
# actually in a repository.
|
||||
@ -1104,6 +1083,15 @@ _lp_bzr_branch_color()
|
||||
}
|
||||
|
||||
|
||||
####################
|
||||
# Wifi link status #
|
||||
####################
|
||||
_lp_wifi()
|
||||
{
|
||||
# Linux
|
||||
sed -n '3s/^ *[^ ]* *[^ ]* *\([0-9]*\).*/\1/p' /proc/net/wireless
|
||||
}
|
||||
|
||||
##################
|
||||
# Battery status #
|
||||
##################
|
||||
@ -1161,7 +1149,7 @@ case "$LP_OS" in
|
||||
{
|
||||
[[ "$LP_ENABLE_BATT" != 1 ]] && return
|
||||
local pmset="$(pmset -g batt | tail -n1)"
|
||||
local bat="$(cut -f2 <<<$pmset)"
|
||||
local bat="$(cut -f2 <<<"$pmset")"
|
||||
bat="${bat%%%*}"
|
||||
case "$pmset" in
|
||||
*charged*)
|
||||
@ -1385,22 +1373,31 @@ _lp_load_color()
|
||||
# System temperature #
|
||||
######################
|
||||
|
||||
_lp_temp_sensors() {
|
||||
_lp_temp_sensors()
|
||||
{
|
||||
# Return the hottest system temperature we get through the sensors command
|
||||
local temperature=0
|
||||
local i
|
||||
for i in $(sensors |
|
||||
sed -n -r "s/^(CPU|SYS|MB|Core|temp).*: *\+([0-9]*)\..°.*/\2/p"); do
|
||||
if [[ $i -gt $temperature ]]; then
|
||||
temperature=$i
|
||||
fi
|
||||
[[ $i -gt $temperature ]] && temperature=$i
|
||||
done
|
||||
}
|
||||
|
||||
_lp_temp_acpi()
|
||||
{
|
||||
local i
|
||||
for i in $(acpi -t | sed 's/.* \([0-9]*\)\.[0-9]* degrees C$/\1/p')
|
||||
do
|
||||
[[ $i -gt $temperature ]] && temperature=$i
|
||||
done
|
||||
echo -ne "$temperature"
|
||||
}
|
||||
|
||||
# Will set _LP_TEMP_FUNCTION so the temperature monitoring feature use an
|
||||
# available command. _LP_TEMP_FUNCTION should return only a numeric value
|
||||
if [[ "$LP_ENABLE_TEMP" = 1 ]]; then
|
||||
if command -v sensors >/dev/null; then
|
||||
if command -v acpi >/dev/null; then
|
||||
_LP_TEMP_FUNCTION=_lp_temp_acpi
|
||||
elif command -v sensors >/dev/null; then
|
||||
_LP_TEMP_FUNCTION=_lp_temp_sensors
|
||||
# elif command -v the_command_you_want_to_use; then
|
||||
# _LP_TEMP_FUNCTION=your_function
|
||||
@ -1414,7 +1411,9 @@ _lp_temperature() {
|
||||
# and colorize it through _lp_color_map.
|
||||
[[ "$LP_ENABLE_TEMP" != 1 ]] && return
|
||||
|
||||
local temperature="$($_LP_TEMP_FUNCTION)"
|
||||
local temperature
|
||||
temperature=0
|
||||
$_LP_TEMP_FUNCTION
|
||||
if [[ $temperature -ge $LP_TEMP_THRESHOLD ]]; then
|
||||
echo -ne "${LP_MARK_TEMP}$(_lp_color_map $temperature 120)$temperature°${NO_COL}"
|
||||
fi
|
||||
@ -1424,24 +1423,16 @@ _lp_temperature() {
|
||||
# DESIGN #
|
||||
##########
|
||||
|
||||
|
||||
# Sed expression using extended regexp to remove shell codes around terminal
|
||||
# escape sequences
|
||||
_LP_CLEAN_ESC="$(printf "s,%q|%q,,g" "$_LP_OPEN_ESC" "$_LP_CLOSE_ESC")"
|
||||
|
||||
# Remove all colors and escape characters of the given string and return a pure text
|
||||
_lp_as_text()
|
||||
{
|
||||
# Remove colors from the computed prompt
|
||||
case "$LP_OS" in
|
||||
Linux|FreeBSD|OpenBSD|SunOS) local pst="$(echo $1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" ;;
|
||||
Darwin) local pst="$(echo $1 | sed -E "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" ;;
|
||||
esac
|
||||
|
||||
|
||||
# Remove escape sequences
|
||||
# FIXME check the zsh compatibility
|
||||
# pst=$(echo $pst | sed "s,\\\\\\[\|\\\\\\],,g")
|
||||
local op="$(printf "%q" "$_LP_OPEN_ESC")"
|
||||
local cl="$(printf "%q" "$_LP_CLOSE_ESC")"
|
||||
pst="$(echo $pst | sed "s,$op\|$cl,,g")" # replace all open _or_ close tags with nothing
|
||||
|
||||
echo -n "$pst"
|
||||
echo -n "$1" | sed -$_LP_SED_EXTENDED "s/\x1B\[[0-9;]*[mK]//g;$_LP_CLEAN_ESC"
|
||||
}
|
||||
|
||||
_lp_title()
|
||||
@ -1449,24 +1440,7 @@ _lp_title()
|
||||
[[ "$LP_ENABLE_TITLE" != "1" ]] && return
|
||||
|
||||
# Get the current computed prompt as pure text
|
||||
local txt="$(_lp_as_text "$1")"
|
||||
|
||||
# Use it in the window's title
|
||||
# Escapes whill tells bash to ignore the non-printing control characters when calculating the width of the prompt.
|
||||
# Otherwise line editing commands will mess the cursor positionning
|
||||
case "$TERM" in
|
||||
screen*)
|
||||
[[ "$LP_ENABLE_SCREEN_TITLE" != "1" ]] && return
|
||||
local title="${LP_SCREEN_TITLE_OPEN}${txt}${LP_SCREEN_TITLE_CLOSE}"
|
||||
;;
|
||||
linux*)
|
||||
local title=""
|
||||
;;
|
||||
*)
|
||||
local title="${_LP_OPEN_ESC}${LP_TITLE_OPEN}${txt}${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
|
||||
;;
|
||||
esac
|
||||
echo -n "${title}"
|
||||
echo -n "${_LP_OPEN_ESC}${LP_TITLE_OPEN}$(_lp_as_text "$1")${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
|
||||
}
|
||||
|
||||
# Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion
|
||||
@ -1581,15 +1555,8 @@ _lp_set_prompt()
|
||||
local IFS="$(echo -e ' \t')
|
||||
" # space, tab, LF
|
||||
|
||||
# execute the old prompt if not on Mac OS X (Mountain) Lion
|
||||
case "$LP_OS" in
|
||||
Linux|FreeBSD|OpenBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;;
|
||||
Darwin)
|
||||
case "$(LP_DWIN_KERNEL_REL_VER)" in
|
||||
11|12) update_terminal_cwd ;;
|
||||
*) $LP_OLD_PROMPT_COMMAND ;;
|
||||
esac ;;
|
||||
esac
|
||||
# execute the old prompt
|
||||
eval "$LP_OLD_PROMPT_COMMAND"
|
||||
|
||||
# left of main prompt: space at right
|
||||
LP_JOBS="$(_lp_sr "$(_lp_jobcount_color)")"
|
||||
@ -1605,19 +1572,36 @@ _lp_set_prompt()
|
||||
LP_PROXY=
|
||||
fi
|
||||
|
||||
# right of main prompt: space at left
|
||||
LP_VENV="$(_lp_sl "$(_lp_virtualenv)")"
|
||||
# if change of working directory
|
||||
# Display the current Python virtual environnement, if available
|
||||
if [[ "$LP_ENABLE_VIRTUALENV,$VIRTUAL_ENV" = 1,?* ]] ; then
|
||||
LP_VENV=" [${LP_COLOR_VIRTUALENV}${VIRTUAL_ENV##*/}${NO_COL}]"
|
||||
else
|
||||
LP_VENV=
|
||||
fi
|
||||
|
||||
LP_RUNTIME=$(_lp_sl "$(_lp_runtime)")
|
||||
|
||||
# if change of working directory
|
||||
if [[ "$LP_OLD_PWD" != "LP:$PWD" ]]; then
|
||||
# Update directory icon for MacOS X
|
||||
$_LP_TERM_UPDATE_DIR
|
||||
|
||||
LP_VCS=""
|
||||
LP_VCS_TYPE=""
|
||||
# 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_PERM: shows a ":"
|
||||
# - colored in green if user has write permission on the current dir
|
||||
# - colored in red if not
|
||||
if [[ "$LP_ENABLE_PERM" = 1 ]]; then
|
||||
if [[ -w "${PWD}" ]]; then
|
||||
LP_PERM="${LP_COLOR_WRITE}:${NO_COL}"
|
||||
else
|
||||
LP_PERM="${LP_COLOR_NOWRITE}:${NO_COL}"
|
||||
fi
|
||||
fi
|
||||
|
||||
_lp_shorten_path # set LP_PWD
|
||||
|
||||
if _lp_are_vcs_enabled; then
|
||||
LP_VCS="$(_lp_git_branch_color)"
|
||||
@ -1684,7 +1668,7 @@ _lp_set_prompt()
|
||||
source "$LP_PS1_FILE"
|
||||
fi
|
||||
|
||||
if [[ -z $LP_PS1 ]] ; then
|
||||
if [[ -z "$LP_PS1" ]] ; then
|
||||
# add title escape time, jobs, load and battery
|
||||
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_TEMP}${LP_JOBS}"
|
||||
# add user, host and permissions colon
|
||||
@ -1698,7 +1682,7 @@ _lp_set_prompt()
|
||||
PS1="${PS1}${LP_VCS}"
|
||||
|
||||
# add return code and prompt mark
|
||||
PS1="${PS1}${LP_RUNTIME}${LP_ERR}${LP_MARK}${LP_PS1_POSTFIX}"
|
||||
PS1="${PS1}${LP_RUNTIME}${LP_ERR}${LP_MARK_PREFIX}${LP_MARK}${LP_PS1_POSTFIX}"
|
||||
|
||||
# "invisible" parts
|
||||
# Get the current prompt on the fly and make it a title
|
||||
@ -1760,9 +1744,9 @@ prompt_off()
|
||||
{
|
||||
PS1=$LP_OLD_PS1
|
||||
if $_LP_SHELL_bash; then
|
||||
PROMPT_COMMAND=$LP_OLD_PROMPT_COMMAND
|
||||
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
|
||||
else # zsh
|
||||
precmd=$LP_OLD_PROMPT_COMMAND
|
||||
precmd="$LP_OLD_PROMPT_COMMAND"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -1771,9 +1755,9 @@ prompt_OFF()
|
||||
{
|
||||
PS1="\$ "
|
||||
if $_LP_SHELL_bash; then
|
||||
PROMPT_COMMAND=$LP_OLD_PROMPT_COMMAND
|
||||
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
|
||||
else # zsh
|
||||
precmd=$LP_OLD_PROMPT_COMMAND
|
||||
precmd="$LP_OLD_PROMPT_COMMAND"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,8 @@ LP_ENABLE_TEMP=1
|
||||
LP_TIME_ANALOG=0
|
||||
|
||||
# Use the liquid prompt as the title of the terminal window
|
||||
# This may not work properly on exotic terminals, thus the
|
||||
# The content is not customizable, the implementation is very basic,
|
||||
# and this may not work properly on exotic terminals, thus the
|
||||
# recommended value is 0
|
||||
# See LP_TITLE_OPEN and LP_TITLE_CLOSE to change escape characters to adapt this
|
||||
# feature to your specific terminal.
|
||||
|
Loading…
Reference in New Issue
Block a user