2012-08-04 06:05:03 -04:00
|
|
|
################################################################################
|
|
|
|
# LIQUID PROMPT
|
2014-12-09 01:27:11 -05:00
|
|
|
# An intelligent and non-intrusive prompt for Bash and zsh
|
2012-08-04 06:05:03 -04:00
|
|
|
################################################################################
|
|
|
|
|
2012-07-07 05:35:58 -04:00
|
|
|
|
|
|
|
# Licensed under the AGPL version 3
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-08-04 06:05:03 -04:00
|
|
|
###########
|
|
|
|
# AUTHORS #
|
|
|
|
###########
|
|
|
|
|
2013-09-24 16:44:25 -04:00
|
|
|
# Alex Prengère <alexprengere@gmail.com> # Untracked git files
|
|
|
|
# Anthony Gelibert <anthony.gelibert@me.com> # Several fix
|
2013-03-13 07:14:48 -04:00
|
|
|
# Aurelien Requiem <aurelien@requiem.fr> # Major clean refactoring, variable path length, error codes, several bugfixes.
|
2013-09-24 16:44:25 -04:00
|
|
|
# Brendan Fahy <bmfahy@gmail.com> # Postfix variable
|
2013-03-13 07:14:48 -04:00
|
|
|
# Clément Mathieu <clement@unportant.info> # Bazaar support
|
2013-09-24 16:44:25 -04:00
|
|
|
# David Loureiro <david.loureiro@sysfera.com> # Small portability fix
|
2013-05-20 10:47:31 -04:00
|
|
|
# Étienne Deparis <etienne@depar.is> # Fossil support
|
2013-03-13 07:14:48 -04:00
|
|
|
# Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir.
|
2013-12-16 16:30:54 -05:00
|
|
|
# François Schmidts <francois.schmidts@gmail.com> # Initial PROMPT_DIRTRIM support
|
2013-03-13 07:14:48 -04:00
|
|
|
# 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.
|
2013-09-24 16:44:25 -04:00
|
|
|
# Joris Vaillant <joris.vaillant@gmail.com> # Small git fix
|
|
|
|
# Luc Didry <luc@fiat-tux.fr> # ZSH port, several fix
|
2013-03-13 07:14:48 -04:00
|
|
|
# Ludovic Rousseau <ludovic.rousseau@gmail.com> # Lot of bugfixes.
|
2013-06-11 13:32:02 -04:00
|
|
|
# Markus Dreseler <github@dreseler.de> # Runtime of last command
|
2013-09-24 16:44:25 -04:00
|
|
|
# Nicolas Lacourte <nicolas@dotinfra.fr> # Screen title
|
2013-11-30 10:06:41 -05:00
|
|
|
# nojhan <nojhan@gmail.com> # Original author.
|
|
|
|
# Olivier Mengué <dolmen@cpan.org> # Major optimizations, refactorings everywhere; current maintainer
|
2013-09-24 16:44:25 -04:00
|
|
|
# Poil <poil@quake.fr> # Speed improvements
|
2014-01-06 13:51:01 -05:00
|
|
|
# Rolf Morel <rolfmorel@gmail.com> # "Shorten path" refactoring and fixes
|
2013-03-13 07:14:48 -04:00
|
|
|
# Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use.
|
|
|
|
# Yann 'Ze' Richard <ze@nbox.org> # Do not fail on missing commands.
|
2016-07-18 16:22:07 -04:00
|
|
|
# Austen Adler <stonewareslord@gmail.com> # ZSH runtime
|
2012-08-04 06:05:03 -04:00
|
|
|
|
|
|
|
# See the README.md file for a summary of features.
|
|
|
|
|
2014-01-07 16:22:09 -05:00
|
|
|
# Issue #161: do not load if not an interactive shell
|
2014-05-30 16:40:01 -04:00
|
|
|
test -z "$TERM" -o "x$TERM" = xdumb && return
|
2014-01-07 16:22:09 -05:00
|
|
|
|
2012-08-14 06:08:43 -04:00
|
|
|
# Check for recent enough version of bash.
|
2016-07-18 16:22:07 -04:00
|
|
|
if test -n "${BASH_VERSION-}" -a -n "$PS1" ; then
|
2012-08-11 18:46:05 -04:00
|
|
|
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( bmajor < 3 || ( bmajor == 3 && bminor < 2 ) )); then
|
2012-08-11 18:46:05 -04:00
|
|
|
unset bash bmajor bminor
|
|
|
|
return
|
|
|
|
fi
|
2014-03-14 14:04:32 -04:00
|
|
|
|
2012-07-17 03:23:44 -04:00
|
|
|
unset bash bmajor bminor
|
2012-08-11 18:46:05 -04:00
|
|
|
|
2013-05-04 18:11:18 -04:00
|
|
|
_LP_SHELL_bash=true
|
|
|
|
_LP_SHELL_zsh=false
|
2012-08-13 17:15:24 -04:00
|
|
|
_LP_OPEN_ESC="\["
|
2012-08-13 18:37:36 -04:00
|
|
|
_LP_CLOSE_ESC="\]"
|
2016-07-18 16:22:07 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
_LP_USER_SYMBOL="\u"
|
|
|
|
_LP_HOST_SYMBOL="\h"
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_FQDN_SYMBOL="\H"
|
2013-05-04 16:58:12 -04:00
|
|
|
_LP_TIME_SYMBOL="\t"
|
2013-06-12 20:13:17 -04:00
|
|
|
_LP_MARK_SYMBOL='\$'
|
2013-12-17 15:39:48 -05:00
|
|
|
_LP_PWD_SYMBOL="\\w"
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_DIR_SYMBOL="\\W"
|
|
|
|
|
|
|
|
_LP_FIRST_INDEX=0
|
|
|
|
_LP_PERCENT='%' # must be escaped on zsh
|
|
|
|
_LP_BACKSLASH='\\' # must be escaped on bash
|
|
|
|
|
|
|
|
# Escape the given strings
|
|
|
|
# Must be used for all strings injected in PS1 that may comes from remote sources,
|
|
|
|
# like $PWD, VCS branch names...
|
|
|
|
_lp_escape()
|
|
|
|
{
|
|
|
|
echo -nE "${1//\\/\\\\}"
|
|
|
|
}
|
|
|
|
|
2014-02-14 12:17:34 -05:00
|
|
|
# Disable the DEBUG trap used by the RUNTIME feature
|
|
|
|
# (in case we are reloading LP in the same shell after disabling
|
|
|
|
# the feature in .liquidpromptrc)
|
|
|
|
# FIXME this doesn't seem to work :(
|
2016-07-18 16:22:07 -04:00
|
|
|
[[ -n "${LP_ENABLE_RUNTIME-}" ]] && trap - DEBUG
|
|
|
|
elif test -n "${ZSH_VERSION-}" ; then
|
2013-05-04 18:11:18 -04:00
|
|
|
_LP_SHELL_bash=false
|
|
|
|
_LP_SHELL_zsh=true
|
2012-08-13 17:15:24 -04:00
|
|
|
_LP_OPEN_ESC="%{"
|
2012-08-13 18:37:36 -04:00
|
|
|
_LP_CLOSE_ESC="%}"
|
2016-07-18 16:22:07 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
_LP_USER_SYMBOL="%n"
|
|
|
|
_LP_HOST_SYMBOL="%m"
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_FQDN_SYMBOL="%M"
|
2013-01-25 07:17:05 -05:00
|
|
|
_LP_TIME_SYMBOL="%*"
|
2013-06-12 20:13:17 -04:00
|
|
|
_LP_MARK_SYMBOL='%(!.#.%%)'
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_PWD_SYMBOL="%~"
|
|
|
|
_LP_DIR_SYMBOL="%1~"
|
|
|
|
|
2013-06-02 05:02:34 -04:00
|
|
|
_LP_FIRST_INDEX=1
|
2014-06-30 18:07:06 -04:00
|
|
|
_LP_PERCENT='%%'
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_BACKSLASH="\\"
|
|
|
|
|
|
|
|
_lp_escape()
|
|
|
|
{
|
|
|
|
arg="${1//\\/\\\\}"
|
|
|
|
echo -nE "${arg//\%/$_LP_PERCENT}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# For ZSH, autoload required functions
|
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
|
|
|
|
# Disable previous hooks as options that set them
|
|
|
|
# may have changed
|
|
|
|
{
|
|
|
|
add-zsh-hook -d precmd _lp_set_prompt
|
|
|
|
add-zsh-hook -d preexec _lp_runtime_before
|
|
|
|
add-zsh-hook -d precmd _lp_runtime_after
|
|
|
|
} >/dev/null
|
2012-08-14 06:08:43 -04:00
|
|
|
else
|
2012-08-14 08:12:33 -04:00
|
|
|
echo "liquidprompt: shell not supported" >&2
|
|
|
|
return
|
2012-07-07 03:32:29 -04:00
|
|
|
fi
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
|
2014-06-27 13:54:00 -04:00
|
|
|
# Store $2 (or $?) as a true/false value in variable named $1
|
|
|
|
# $? is propagated
|
|
|
|
# _lp_bool foo 5
|
|
|
|
# => foo=false
|
|
|
|
# _lp_bool foo 0
|
|
|
|
# => foo=true
|
|
|
|
_lp_bool()
|
|
|
|
{
|
|
|
|
local res=${2:-$?}
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( res )); then
|
2014-07-09 16:50:05 -04:00
|
|
|
eval $1=false
|
2016-07-18 16:22:07 -04:00
|
|
|
else
|
|
|
|
eval $1=true
|
2014-07-09 16:50:05 -04:00
|
|
|
fi
|
2014-06-27 13:54:00 -04:00
|
|
|
return $res
|
|
|
|
}
|
|
|
|
|
2014-01-22 16:56:48 -05:00
|
|
|
# Save $IFS as we want to restore the default value at the beginning of the
|
|
|
|
# prompt function
|
|
|
|
_LP_IFS="$IFS"
|
|
|
|
|
2012-07-22 16:28:50 -04:00
|
|
|
|
|
|
|
###############
|
2012-08-14 05:10:12 -04:00
|
|
|
# OS specific #
|
2012-07-22 16:28:50 -04:00
|
|
|
###############
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
# LP_OS detection, default to Linux
|
2012-07-22 16:11:09 -04:00
|
|
|
case $(uname) in
|
2012-08-14 16:56:44 -04:00
|
|
|
FreeBSD) LP_OS=FreeBSD ;;
|
|
|
|
DragonFly) LP_OS=FreeBSD ;;
|
2013-07-01 07:42:48 -04:00
|
|
|
OpenBSD) LP_OS=OpenBSD ;;
|
2012-08-21 17:35:14 -04:00
|
|
|
Darwin) LP_OS=Darwin ;;
|
2012-08-14 16:56:44 -04:00
|
|
|
SunOS) LP_OS=SunOS ;;
|
|
|
|
*) LP_OS=Linux ;;
|
2012-07-22 16:11:09 -04:00
|
|
|
esac
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-08-14 17:24:55 -04:00
|
|
|
# Get cpu count
|
|
|
|
case "$LP_OS" in
|
2015-01-05 17:32:23 -05:00
|
|
|
Linux) _lp_CPUNUM=$( nproc 2>/dev/null || \grep -c '^[Pp]rocessor' /proc/cpuinfo ) ;;
|
2013-07-01 07:42:48 -04:00
|
|
|
FreeBSD|Darwin|OpenBSD) _lp_CPUNUM=$( sysctl -n hw.ncpu ) ;;
|
2015-01-05 17:32:23 -05:00
|
|
|
SunOS) _lp_CPUNUM=$( kstat -m cpu_info | \grep -c "module: cpu_info" ) ;;
|
2012-08-14 17:24:55 -04:00
|
|
|
esac
|
2012-07-20 06:50:05 -04:00
|
|
|
|
2013-12-27 13:14:48 -05:00
|
|
|
# Extended regexp patterns for sed
|
|
|
|
# GNU/BSD sed
|
|
|
|
_LP_SED_EXTENDED=r
|
|
|
|
[[ "$LP_OS" = Darwin ]] && _LP_SED_EXTENDED=E
|
|
|
|
|
2012-07-20 06:50:05 -04:00
|
|
|
|
|
|
|
# get current load
|
2012-08-14 18:11:34 -04:00
|
|
|
case "$LP_OS" in
|
|
|
|
Linux)
|
|
|
|
_lp_cpu_load () {
|
2016-07-18 16:22:07 -04:00
|
|
|
local eol
|
|
|
|
read lp_cpu_load eol < /proc/loadavg
|
2012-08-14 18:11:34 -04:00
|
|
|
}
|
|
|
|
;;
|
2013-06-17 15:47:51 -04:00
|
|
|
FreeBSD|Darwin|OpenBSD)
|
2012-08-14 18:11:34 -04:00
|
|
|
_lp_cpu_load () {
|
2016-07-18 16:22:07 -04:00
|
|
|
local bol eol
|
2013-06-17 15:09:43 -04:00
|
|
|
# If you have problems with syntax coloring due to the following
|
|
|
|
# line, do this: ln -s liquidprompt liquidprompt.bash
|
|
|
|
# and edit liquidprompt.bash
|
2016-07-18 16:22:07 -04:00
|
|
|
read bol lp_cpu_load eol <<<"$( LANG=C sysctl -n vm.loadavg )"
|
2012-08-14 18:11:34 -04:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
SunOS)
|
|
|
|
_lp_cpu_load () {
|
2016-07-18 16:22:07 -04:00
|
|
|
read lp_cpu_load <<<"$( LANG=C uptime | awk '{print substr($10,0,length($10))}' )"
|
2012-08-14 18:11:34 -04:00
|
|
|
}
|
|
|
|
esac
|
2012-07-23 10:05:49 -04:00
|
|
|
|
2012-07-17 03:50:30 -04:00
|
|
|
|
2012-08-14 05:10:12 -04:00
|
|
|
#################
|
|
|
|
# CONFIGURATION #
|
|
|
|
#################
|
|
|
|
|
2012-08-21 06:13:06 -04:00
|
|
|
# The following code is run just once. But it is encapsulated in a function
|
|
|
|
# to benefit of 'local' variables.
|
|
|
|
#
|
|
|
|
# What we do here:
|
2014-12-09 01:27:11 -05:00
|
|
|
# 1. Setup variables that can be used by the user: the "API" of Liquid Prompt
|
2012-08-21 01:51:40 -04:00
|
|
|
# for config/theme. Those variables are local to the function.
|
|
|
|
# In practice, this is only color variables.
|
|
|
|
# 2. Setup default values
|
|
|
|
# 3. Load the configuration
|
2012-08-14 05:10:12 -04:00
|
|
|
_lp_source_config()
|
|
|
|
{
|
2012-08-21 01:14:00 -04:00
|
|
|
|
2012-08-21 01:21:25 -04:00
|
|
|
# TermInfo feature detection
|
2012-08-21 01:52:25 -04:00
|
|
|
local ti_sgr0="$( { tput sgr0 || tput me ; } 2>/dev/null )"
|
|
|
|
local ti_bold="$( { tput bold || tput md ; } 2>/dev/null )"
|
|
|
|
local ti_setaf
|
2014-03-08 15:52:06 -05:00
|
|
|
local ti_setab
|
|
|
|
if tput setaf 0 >/dev/null 2>&1; then
|
|
|
|
ti_setaf() { tput setaf "$1" ; }
|
|
|
|
elif tput AF 0 >/dev/null 2>&1; then
|
|
|
|
# FreeBSD
|
|
|
|
ti_setaf() { tput AF "$1" ; }
|
|
|
|
elif tput AF 0 0 0 >/dev/null 2>&1; then
|
2013-07-01 07:42:48 -04:00
|
|
|
# OpenBSD
|
2014-03-08 15:52:06 -05:00
|
|
|
ti_setaf() { tput AF "$1" 0 0 ; }
|
2012-08-21 01:21:25 -04:00
|
|
|
else
|
|
|
|
echo "liquidprompt: terminal $TERM not supported" >&2
|
2012-08-21 01:52:25 -04:00
|
|
|
ti_setaf () { : ; }
|
2012-08-21 01:21:25 -04:00
|
|
|
fi
|
2014-03-08 15:52:06 -05:00
|
|
|
if tput setab 0 >/dev/null 2>&1; then
|
|
|
|
ti_setab() { tput setab "$1" ; }
|
|
|
|
elif tput AB 0 >/dev/null 2>&1; then
|
|
|
|
# FreeBSD
|
|
|
|
ti_setab() { tput AB "$1" ; }
|
|
|
|
elif tput AB 0 0 0 >/dev/null 2>&1; then
|
|
|
|
# OpenBSD
|
|
|
|
ti_setab() { tput AB "$1" 0 0 ; }
|
|
|
|
else
|
|
|
|
echo "liquidprompt: terminal $TERM not supported" >&2
|
|
|
|
ti_setab() { : ; }
|
|
|
|
fi
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:31:17 -04:00
|
|
|
# Colors: variables are local so they will have a value only
|
|
|
|
# during config loading and will not conflict with other values
|
|
|
|
# with the same names defined by the user outside the config.
|
2012-08-21 01:52:25 -04:00
|
|
|
local BOLD="${_LP_OPEN_ESC}${ti_bold}${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local BLACK="${_LP_OPEN_ESC}$(ti_setaf 0)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_GRAY="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 0)${_LP_CLOSE_ESC}"
|
|
|
|
local WHITE="${_LP_OPEN_ESC}$(ti_setaf 7)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_WHITE="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 7)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local RED="${_LP_OPEN_ESC}$(ti_setaf 1)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_RED="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 1)${_LP_CLOSE_ESC}"
|
2014-03-08 15:52:06 -05:00
|
|
|
local WARN_RED="${_LP_OPEN_ESC}$(ti_setaf 0 ; ti_setab 1)${_LP_CLOSE_ESC}"
|
|
|
|
local CRIT_RED="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 7 ; ti_setab 1)${_LP_CLOSE_ESC}"
|
|
|
|
local DANGER_RED="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 3 ; ti_setab 1)${_LP_CLOSE_ESC}"
|
2012-08-14 04:56:34 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local GREEN="${_LP_OPEN_ESC}$(ti_setaf 2)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_GREEN="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 2)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local YELLOW="${_LP_OPEN_ESC}$(ti_setaf 3)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_YELLOW="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 3)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local BLUE="${_LP_OPEN_ESC}$(ti_setaf 4)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_BLUE="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 4)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local PURPLE="${_LP_OPEN_ESC}$(ti_setaf 5)${_LP_CLOSE_ESC}"
|
|
|
|
local PINK="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 5)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
local CYAN="${_LP_OPEN_ESC}$(ti_setaf 6)${_LP_CLOSE_ESC}"
|
|
|
|
local BOLD_CYAN="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 6)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-21 01:14:00 -04:00
|
|
|
# NO_COL is special: it will be used at runtime, not just during config loading
|
2012-08-21 01:52:25 -04:00
|
|
|
NO_COL="${_LP_OPEN_ESC}${ti_sgr0}${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2014-06-30 18:32:46 -04:00
|
|
|
# compute the hash of the hostname
|
|
|
|
# and get the corresponding number in [1-6] (red,green,yellow,blue,purple or cyan)
|
|
|
|
# FIXME check portability of cksum and add more formats (bold? 256 colors?)
|
|
|
|
local hash=$(( 1 + $(hostname | cksum | cut -d " " -f 1) % 6 ))
|
|
|
|
LP_COLOR_HOST_HASH="${_LP_OPEN_ESC}$(ti_setaf $hash)${_LP_CLOSE_ESC}"
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
unset ti_sgr0 ti_bold
|
|
|
|
unset -f ti_setaf ti_setab
|
2012-08-21 01:05:15 -04:00
|
|
|
|
2012-08-21 01:07:34 -04:00
|
|
|
|
2012-08-21 01:51:40 -04:00
|
|
|
# Default values (globals)
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
|
|
|
|
LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60}
|
2013-04-21 10:16:06 -04:00
|
|
|
LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-60}
|
2013-06-11 13:32:02 -04:00
|
|
|
LP_RUNTIME_THRESHOLD=${LP_RUNTIME_THRESHOLD:-2}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
|
|
|
|
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
|
2013-12-17 15:39:48 -05:00
|
|
|
LP_PATH_DEFAULT="${LP_PATH_DEFAULT:-$_LP_PWD_SYMBOL}"
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
|
2013-01-11 04:15:12 -05:00
|
|
|
LP_USER_ALWAYS=${LP_USER_ALWAYS:-1}
|
2013-03-13 07:30:41 -04:00
|
|
|
LP_PERCENTS_ALWAYS=${LP_PERCENTS_ALWAYS:-1}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_PS1=${LP_PS1:-""}
|
2014-11-16 10:54:22 -05:00
|
|
|
LP_RPS1=${LP_RPS1:-""}
|
2013-01-10 11:18:45 -05:00
|
|
|
LP_PS1_PREFIX=${LP_PS1_PREFIX:-""}
|
2013-04-22 15:16:56 -04:00
|
|
|
LP_PS1_POSTFIX=${LP_PS1_POSTFIX:-""}
|
2012-08-21 01:07:34 -04:00
|
|
|
|
|
|
|
LP_ENABLE_PERM=${LP_ENABLE_PERM:-1}
|
|
|
|
LP_ENABLE_SHORTEN_PATH=${LP_ENABLE_SHORTEN_PATH:-1}
|
|
|
|
LP_ENABLE_PROXY=${LP_ENABLE_PROXY:-1}
|
2013-04-21 10:16:06 -04:00
|
|
|
LP_ENABLE_TEMP=${LP_ENABLE_TEMP:-1}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_ENABLE_JOBS=${LP_ENABLE_JOBS:-1}
|
|
|
|
LP_ENABLE_LOAD=${LP_ENABLE_LOAD:-1}
|
|
|
|
LP_ENABLE_BATT=${LP_ENABLE_BATT:-1}
|
|
|
|
LP_ENABLE_GIT=${LP_ENABLE_GIT:-1}
|
|
|
|
LP_ENABLE_SVN=${LP_ENABLE_SVN:-1}
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_ENABLE_OHMYGIT=${LP_ENABLE_OHMYGIT:-0}
|
2014-03-11 14:01:01 -04:00
|
|
|
LP_ENABLE_VCSH=${LP_ENABLE_VCSH:-1}
|
2012-12-28 20:42:29 -05:00
|
|
|
LP_ENABLE_FOSSIL=${LP_ENABLE_FOSSIL:-1}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
|
2013-01-17 11:20:15 -05:00
|
|
|
LP_ENABLE_BZR=${LP_ENABLE_BZR:-1}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
|
2015-03-26 00:25:54 -04:00
|
|
|
LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-1}
|
2012-11-03 17:09:50 -04:00
|
|
|
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
|
2014-05-15 11:45:26 -04:00
|
|
|
LP_ENABLE_SCLS=${LP_ENABLE_SCLS:-1}
|
2013-01-04 06:13:00 -05:00
|
|
|
LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
|
2013-01-10 11:18:45 -05:00
|
|
|
LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0}
|
2013-03-08 05:48:21 -05:00
|
|
|
LP_ENABLE_SCREEN_TITLE=${LP_ENABLE_SCREEN_TITLE:-0}
|
2013-03-11 19:02:04 -04:00
|
|
|
LP_ENABLE_SSH_COLORS=${LP_ENABLE_SSH_COLORS:-0}
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_ENABLE_FQDN=${LP_ENABLE_FQDN:-0}
|
2013-12-17 18:18:22 -05:00
|
|
|
# LP_DISABLED_VCS_PATH="${LP_DISABLED_VCS_PATH}"
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_ENABLE_SUDO=${LP_ENABLE_SUDO:-0}
|
2013-12-17 18:18:22 -05:00
|
|
|
|
2014-06-27 19:49:56 -04:00
|
|
|
LP_MARK_DEFAULT="${LP_MARK_DEFAULT:-$_LP_MARK_SYMBOL}"
|
2013-12-17 18:18:22 -05:00
|
|
|
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:-"±"}"
|
2014-03-11 14:01:01 -04:00
|
|
|
LP_MARK_VCSH="${LP_MARK_VCSH:-"|"}"
|
2013-12-17 18:18:22 -05:00
|
|
|
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:-" … "}"
|
2014-03-08 23:04:35 -05:00
|
|
|
LP_MARK_PREFIX="${LP_MARK_PREFIX:-" "}"
|
2012-08-21 01:07:34 -04:00
|
|
|
|
2013-04-30 08:03:37 -04:00
|
|
|
LP_COLOR_PATH=${LP_COLOR_PATH:-$BOLD}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_PATH_ROOT=${LP_COLOR_PATH_ROOT:-$BOLD_YELLOW}
|
|
|
|
LP_COLOR_PROXY=${LP_COLOR_PROXY:-$BOLD_BLUE}
|
|
|
|
LP_COLOR_JOB_D=${LP_COLOR_JOB_D:-$YELLOW}
|
|
|
|
LP_COLOR_JOB_R=${LP_COLOR_JOB_R:-$BOLD_YELLOW}
|
|
|
|
LP_COLOR_JOB_Z=${LP_COLOR_JOB_Z:-$BOLD_YELLOW}
|
|
|
|
LP_COLOR_ERR=${LP_COLOR_ERR:-$PURPLE}
|
2013-04-30 08:03:37 -04:00
|
|
|
LP_COLOR_MARK=${LP_COLOR_MARK:-$BOLD}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_MARK_ROOT=${LP_COLOR_MARK_ROOT:-$BOLD_RED}
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_COLOR_MARK_SUDO=${LP_COLOR_MARK_SUDO:-$LP_COLOR_MARK_ROOT}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_USER_LOGGED=${LP_COLOR_USER_LOGGED:-""}
|
|
|
|
LP_COLOR_USER_ALT=${LP_COLOR_USER_ALT:-$BOLD}
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_COLOR_USER_ROOT=${LP_COLOR_USER_ROOT:-$BOLD_YELLOW}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_HOST=${LP_COLOR_HOST:-""}
|
2012-09-25 15:09:51 -04:00
|
|
|
LP_COLOR_SSH=${LP_COLOR_SSH:-$BLUE}
|
2013-03-14 13:15:55 -04:00
|
|
|
LP_COLOR_SU=${LP_COLOR_SU:-$BOLD_YELLOW}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_TELNET=${LP_COLOR_TELNET:-$WARN_RED}
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_COLOR_X11_ON=${LP_COLOR_X11_ON:-$GREEN}
|
|
|
|
LP_COLOR_X11_OFF=${LP_COLOR_X11_OFF:-$YELLOW}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_WRITE=${LP_COLOR_WRITE:-$GREEN}
|
|
|
|
LP_COLOR_NOWRITE=${LP_COLOR_NOWRITE:-$RED}
|
|
|
|
LP_COLOR_UP=${LP_COLOR_UP:-$GREEN}
|
|
|
|
LP_COLOR_COMMITS=${LP_COLOR_COMMITS:-$YELLOW}
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_COLOR_COMMITS_BEHIND=${LP_COLOR_COMMITS_BEHIND:-$BOLD_RED}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_COLOR_CHANGES=${LP_COLOR_CHANGES:-$RED}
|
|
|
|
LP_COLOR_DIFF=${LP_COLOR_DIFF:-$PURPLE}
|
|
|
|
LP_COLOR_CHARGING_ABOVE=${LP_COLOR_CHARGING_ABOVE:-$GREEN}
|
|
|
|
LP_COLOR_CHARGING_UNDER=${LP_COLOR_CHARGING_UNDER:-$YELLOW}
|
|
|
|
LP_COLOR_DISCHARGING_ABOVE=${LP_COLOR_DISCHARGING_ABOVE:-$YELLOW}
|
|
|
|
LP_COLOR_DISCHARGING_UNDER=${LP_COLOR_DISCHARGING_UNDER:-$RED}
|
|
|
|
LP_COLOR_TIME=${LP_COLOR_TIME:-$BLUE}
|
2013-02-26 08:18:58 -05:00
|
|
|
LP_COLOR_IN_MULTIPLEXER=${LP_COLOR_IN_MULTIPLEXER:-$BOLD_BLUE}
|
2013-06-11 13:32:02 -04:00
|
|
|
LP_COLOR_RUNTIME=${LP_COLOR_RUNTIME:-$YELLOW}
|
2014-03-08 00:28:02 -05:00
|
|
|
LP_COLOR_VIRTUALENV=${LP_COLOR_VIRTUALENV:-$CYAN}
|
2012-08-21 01:07:34 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -z "${LP_COLORMAP-}" ]]; then
|
|
|
|
LP_COLORMAP=(
|
|
|
|
"" # 0
|
|
|
|
"$GREEN" # 1
|
|
|
|
"$BOLD_GREEN" # 2
|
|
|
|
"$YELLOW" # 3
|
|
|
|
"$BOLD_YELLOW" # 4
|
|
|
|
"$RED" # 5
|
|
|
|
"$BOLD_RED" # 6
|
|
|
|
"$WARN_RED" # 7
|
|
|
|
"$CRIT_RED" # 8
|
|
|
|
"$DANGER_RED" # 9
|
|
|
|
)
|
|
|
|
fi
|
2012-08-14 09:06:58 -04:00
|
|
|
|
2013-06-12 09:11:13 -04:00
|
|
|
# Debugging flags
|
|
|
|
LP_DEBUG_TIME=${LP_DEBUG_TIME:-0}
|
2012-08-14 09:06:58 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
|
|
|
|
local configfile
|
|
|
|
|
2012-08-21 01:03:52 -04:00
|
|
|
# Default config file may be the XDG standard ~/.config/liquidpromptrc,
|
|
|
|
# but heirloom dotfile has priority.
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -f "$HOME/.liquidpromptrc" ]]; then
|
2012-08-14 05:10:12 -04:00
|
|
|
configfile="$HOME/.liquidpromptrc"
|
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
local first
|
|
|
|
local search
|
|
|
|
# trailing ":" is so that ${search#*:} always removes something
|
|
|
|
search="${XDG_CONFIG_HOME:-"$HOME/.config"}:${XDG_CONFIG_DIRS:-/etc/xdg}:"
|
|
|
|
while [[ -n "$search" ]]; do
|
|
|
|
first="${search%%:*}"
|
|
|
|
search="${search#*:}"
|
|
|
|
if [[ -f "$first/liquidpromptrc" ]]; then
|
|
|
|
configfile="$first/liquidpromptrc"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
2012-08-14 05:10:12 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
|
|
|
|
if [[ -n "$configfile" ]]; then
|
2012-08-14 05:10:12 -04:00
|
|
|
source "$configfile"
|
2016-07-18 16:22:07 -04:00
|
|
|
elif [[ -f "/etc/liquidpromptrc" ]]; then
|
|
|
|
source "/etc/liquidpromptrc"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete this code in version 1.11
|
|
|
|
if [[ -n "${LP_COLORMAP_1-}" ]]; then
|
|
|
|
echo "liquidprompt: LP_COLORMAP_x variables are deprecated. Update your theme to use LP_COLORMAP array." >&2
|
|
|
|
LP_COLORMAP=(
|
|
|
|
"$LP_COLORMAP_0"
|
|
|
|
"$LP_COLORMAP_1"
|
|
|
|
"$LP_COLORMAP_2"
|
|
|
|
"$LP_COLORMAP_3"
|
|
|
|
"$LP_COLORMAP_4"
|
|
|
|
"$LP_COLORMAP_5"
|
|
|
|
"$LP_COLORMAP_6"
|
|
|
|
"$LP_COLORMAP_7"
|
|
|
|
"$LP_COLORMAP_8"
|
|
|
|
"$LP_COLORMAP_9"
|
|
|
|
)
|
|
|
|
unset LP_COLORMAP_0 LP_COLORMAP_1 LP_COLORMAP_2 LP_COLORMAP_3 LP_COLORMAP_4 \
|
|
|
|
LP_COLORMAP_5 LP_COLORMAP_6 LP_COLORMAP_7 LP_COLORMAP_8 LP_COLORMAP_9
|
2012-08-14 05:10:12 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
# do source config files
|
|
|
|
_lp_source_config
|
2016-07-18 16:22:07 -04:00
|
|
|
unset -f _lp_source_config
|
|
|
|
|
|
|
|
# Disable feature if the tool is not installed
|
|
|
|
_lp_require_tool()
|
|
|
|
{
|
|
|
|
(( LP_ENABLE_$1 )) && { command -v $2 >/dev/null || eval LP_ENABLE_$1=0 ; }
|
|
|
|
}
|
|
|
|
|
|
|
|
_lp_require_tool GIT git
|
|
|
|
_lp_require_tool SVN svn
|
|
|
|
_lp_require_tool FOSSIL fossil
|
|
|
|
_lp_require_tool HG hg
|
|
|
|
_lp_require_tool BZR bzr
|
|
|
|
|
|
|
|
if [[ "$LP_OS" = Darwin ]]; then
|
|
|
|
_lp_require_tool BATT pmset
|
|
|
|
else
|
|
|
|
_lp_require_tool BATT acpi
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset -f _lp_require_tool
|
|
|
|
|
|
|
|
if (( LP_ENABLE_JOBS )); then
|
|
|
|
typeset -i _LP_ENABLE_DETACHED_SESSION _LP_ENABLE_SCREEN _LP_ENABLE_TMUX
|
|
|
|
command -v screen >/dev/null ; _LP_ENABLE_SCREEN=!$?
|
|
|
|
command -v tmux >/dev/null ; _LP_ENABLE_TMUX=!$?
|
|
|
|
(( _LP_ENABLE_DETACHED_SESSIONS = ( _LP_ENABLE_SCREEN || _LP_ENABLE_TMUX ) ))
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use standard path symbols inside Midnight Commander
|
|
|
|
[[ -n "${MC_SID-}" ]] && LP_ENABLE_SHORTEN_PATH=0
|
2012-08-16 10:39:20 -04:00
|
|
|
|
2013-05-04 09:15:26 -04:00
|
|
|
# If we are running in a terminal multiplexer, brackets are colored
|
|
|
|
if [[ "$TERM" == screen* ]]; then
|
2013-05-04 11:06:11 -04:00
|
|
|
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}"
|
2013-12-27 16:41:08 -05:00
|
|
|
(( LP_ENABLE_TITLE = LP_ENABLE_TITLE && LP_ENABLE_SCREEN_TITLE ))
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_TITLE_OPEN="$(printf '\033k')"
|
|
|
|
# "\e\" but on bash \ must be escaped
|
|
|
|
LP_TITLE_CLOSE="$(printf '\033%s' "$_LP_BACKSLASH")"
|
2013-05-04 11:06:11 -04:00
|
|
|
else
|
|
|
|
LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}"
|
|
|
|
LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}"
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_TITLE_OPEN="$(printf '\e]0;')"
|
|
|
|
LP_TITLE_CLOSE="$(printf '\a')"
|
2013-05-04 09:15:26 -04:00
|
|
|
fi
|
|
|
|
|
2013-12-27 16:41:08 -05:00
|
|
|
[[ "_$TERM" == _linux* ]] && LP_ENABLE_TITLE=0
|
|
|
|
|
2013-06-17 15:40:56 -04:00
|
|
|
# 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
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "${TERM_PROGRAM-}" == Apple_Terminal ]] && command -v update_terminal_cwd >/dev/null; then
|
2013-06-17 15:40:56 -04:00
|
|
|
_LP_TERM_UPDATE_DIR=update_terminal_cwd
|
2013-06-23 17:56:00 -04:00
|
|
|
# Remove "update_terminal_cwd; " that has been add by Apple in /et/bashrc.
|
|
|
|
# See issue #196
|
|
|
|
PROMPT_COMMAND="${PROMPT_COMMAND//update_terminal_cwd; /}"
|
2013-06-17 15:40:56 -04:00
|
|
|
else
|
|
|
|
_LP_TERM_UPDATE_DIR=:
|
|
|
|
fi
|
|
|
|
|
2014-01-06 15:38:15 -05:00
|
|
|
# Default value for LP_PERM when LP_ENABLE_PERM is 0
|
|
|
|
LP_PERM=: # without color
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Same as bash '\l', but inlined as a constant as the value will not change
|
|
|
|
# during the shell's life
|
|
|
|
LP_TTYN="$(basename -- "$(tty)" 2>/dev/null)"
|
2013-06-17 15:40:56 -04:00
|
|
|
|
2012-08-16 10:39:20 -04:00
|
|
|
|
2012-08-14 05:10:12 -04:00
|
|
|
|
2012-07-19 09:08:18 -04:00
|
|
|
###############
|
|
|
|
# Who are we? #
|
|
|
|
###############
|
2016-07-18 16:22:07 -04:00
|
|
|
command -v _lp_sudo_check >/dev/null && unset -f _lp_sudo_check
|
2012-07-19 09:08:18 -04:00
|
|
|
|
2012-08-14 06:01:14 -04:00
|
|
|
# Yellow for root, bold if the user is not the login one, else no color.
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( EUID != 0 )); then # if user is not root
|
2013-01-25 06:20:19 -05:00
|
|
|
# if user is not login user
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "${USER}" != "$(logname 2>/dev/null || echo "$LOGNAME")" ]]; then
|
2013-01-25 06:20:19 -05:00
|
|
|
LP_USER="${LP_COLOR_USER_ALT}${_LP_USER_SYMBOL}${NO_COL}"
|
2016-07-18 16:22:07 -04:00
|
|
|
elif (( LP_USER_ALWAYS )); then
|
|
|
|
LP_USER="${LP_COLOR_USER_LOGGED}${_LP_USER_SYMBOL}${NO_COL}"
|
2013-01-25 06:20:19 -05:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_USER=""
|
|
|
|
fi
|
|
|
|
# "sudo -n" is only supported from sudo 1.7.0
|
|
|
|
if (( LP_ENABLE_SUDO )) \
|
|
|
|
&& command -v sudo >/dev/null \
|
|
|
|
&& LC_MESSAGES=C sudo -V | GREP_OPTIONS= \grep -qE '^Sudo version (1(\.([789]\.|[1-9][0-9])|[0-9])|[2-9])'
|
|
|
|
then
|
|
|
|
LP_COLOR_MARK_NO_SUDO="$LP_COLOR_MARK"
|
|
|
|
# Test the code with the commands:
|
|
|
|
# sudo id # sudo, enter your credentials
|
|
|
|
# sudo -K # revoke your credentials
|
|
|
|
_lp_sudo_check()
|
|
|
|
{
|
|
|
|
if sudo -n true 2>/dev/null; then
|
|
|
|
LP_COLOR_MARK=$LP_COLOR_MARK_SUDO
|
|
|
|
else
|
|
|
|
LP_COLOR_MARK=$LP_COLOR_MARK_NO_SUDO
|
|
|
|
fi
|
|
|
|
}
|
2012-07-19 09:08:18 -04:00
|
|
|
fi
|
2013-06-11 16:23:26 -04:00
|
|
|
else # root!
|
2013-01-25 06:20:19 -05:00
|
|
|
LP_USER="${LP_COLOR_USER_ROOT}${_LP_USER_SYMBOL}${NO_COL}"
|
2013-06-11 16:23:26 -04:00
|
|
|
LP_COLOR_MARK="${LP_COLOR_MARK_ROOT}"
|
|
|
|
LP_COLOR_PATH="${LP_COLOR_PATH_ROOT}"
|
2013-06-11 16:54:44 -04:00
|
|
|
# Disable VCS info for all paths
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( ! LP_ENABLE_VCS_ROOT )); then
|
2013-06-12 20:32:20 -04:00
|
|
|
LP_DISABLED_VCS_PATH=/
|
|
|
|
LP_MARK_DISABLED="$_LP_MARK_SYMBOL"
|
|
|
|
fi
|
2013-01-25 06:20:19 -05:00
|
|
|
fi
|
2012-07-19 09:08:18 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Empty _lp_sudo_check if root or sudo disabled
|
|
|
|
if ! command -v _lp_sudo_check >/dev/null; then
|
|
|
|
_lp_sudo_check() { :; }
|
|
|
|
fi
|
|
|
|
|
2012-07-19 09:08:18 -04:00
|
|
|
|
2012-07-17 03:50:30 -04:00
|
|
|
#################
|
|
|
|
# Where are we? #
|
|
|
|
#################
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_connection()
|
2012-07-17 03:50:30 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "${SSH_CLIENT-}${SSH2_CLIENT-}${SSH_TTY-}" ]]; then
|
2012-08-14 09:11:48 -04:00
|
|
|
echo ssh
|
2012-07-17 03:50:30 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
# tmux: see GH #304
|
2012-08-14 09:11:48 -04:00
|
|
|
# TODO check on *BSD
|
2016-07-18 16:22:07 -04:00
|
|
|
local whoami="$(LANG=C who am i)"
|
2013-06-02 06:14:58 -04:00
|
|
|
local sess_parent="$(ps -o comm= -p $PPID 2> /dev/null)"
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ x"$whoami" != *'('* || x"$whoami" = *'(:'* || x"$whoami" = *'(tmux'* ]]; then
|
2012-08-14 09:11:48 -04:00
|
|
|
echo lcl # Local
|
2016-07-18 16:22:07 -04:00
|
|
|
elif [[ "$sess_parent" = "su" || "$sess_parent" = "sudo" ]]; then
|
2013-03-14 13:15:55 -04:00
|
|
|
echo su # Remote su/sudo
|
2012-08-14 09:11:48 -04:00
|
|
|
else
|
|
|
|
echo tel # Telnet
|
|
|
|
fi
|
2012-07-17 03:50:30 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Put the hostname if not locally connected
|
|
|
|
# color it in cyan within SSH, and a warning red if within telnet
|
2014-06-27 19:57:24 -04:00
|
|
|
# else display the host without color
|
2012-08-14 05:43:58 -04:00
|
|
|
# The connection is not expected to change from inside the shell, so we
|
|
|
|
# build this just once
|
2012-09-23 17:07:51 -04:00
|
|
|
LP_HOST=""
|
2012-09-09 16:43:10 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Only process hostname elements if we haven't turned them off
|
|
|
|
if (( LP_HOSTNAME_ALWAYS != -1 )); then
|
|
|
|
|
|
|
|
[[ -r /etc/debian_chroot ]] && LP_HOST="($(< /etc/debian_chroot))"
|
2012-09-23 17:07:51 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Which host symbol should we use?
|
|
|
|
if (( LP_ENABLE_FQDN )); then
|
|
|
|
LP_HOST_SYMBOL="${_LP_FQDN_SYMBOL}"
|
2012-07-17 03:50:30 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_HOST_SYMBOL="${_LP_HOST_SYMBOL}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If we are connected with a X11 support
|
|
|
|
if [[ -n "$DISPLAY" ]]; then
|
|
|
|
LP_HOST="${LP_COLOR_X11_ON}${LP_HOST}@${NO_COL}"
|
|
|
|
else
|
|
|
|
LP_HOST="${LP_COLOR_X11_OFF}${LP_HOST}@${NO_COL}"
|
2012-07-17 03:50:30 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
|
|
|
|
case "$(_lp_connection)" in
|
|
|
|
lcl)
|
|
|
|
if (( LP_HOSTNAME_ALWAYS )); then
|
|
|
|
LP_HOST+="${LP_COLOR_HOST}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
else
|
|
|
|
# FIXME do we want to display the chroot if local?
|
|
|
|
LP_HOST="" # no hostname if local
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
ssh)
|
|
|
|
# If we want a different color for each host
|
|
|
|
(( LP_ENABLE_SSH_COLORS )) && LP_COLOR_SSH="$LP_COLOR_HOST_HASH"
|
|
|
|
LP_HOST+="${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
;;
|
|
|
|
su)
|
|
|
|
LP_HOST+="${LP_COLOR_SU}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
;;
|
|
|
|
tel)
|
|
|
|
LP_HOST+="${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
LP_HOST+="${_LP_HOST_SYMBOL}" # defaults to no color
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
fi
|
2012-07-17 03:50:30 -04:00
|
|
|
|
2012-08-14 05:43:58 -04:00
|
|
|
# Useless now, so undefine
|
2016-07-18 16:22:07 -04:00
|
|
|
unset -f _lp_connection
|
2012-07-17 03:50:30 -04:00
|
|
|
|
|
|
|
|
2014-03-14 14:04:32 -04:00
|
|
|
_lp_get_home_tilde_collapsed()
|
|
|
|
{
|
2014-06-02 17:34:46 -04:00
|
|
|
local tilde="~"
|
2014-07-09 16:52:56 -04:00
|
|
|
echo "${PWD/#$HOME/$tilde}"
|
2014-03-14 14:04:32 -04:00
|
|
|
}
|
|
|
|
|
2013-11-30 17:54:01 -05:00
|
|
|
# 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
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_shorten_path()
|
2012-07-29 16:19:06 -04:00
|
|
|
{
|
2013-12-16 18:58:17 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( ! LP_ENABLE_SHORTEN_PATH )); then
|
|
|
|
# We are not supposed to come here often as this case is already
|
|
|
|
# optimized at install time
|
|
|
|
LP_PWD="${LP_COLOR_PATH}${LP_PATH_DEFAULT}$NO_COL"
|
2012-08-16 09:16:48 -04:00
|
|
|
return
|
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
local ret=
|
2013-11-30 17:54:01 -05:00
|
|
|
|
2014-03-14 14:04:32 -04:00
|
|
|
local p="$(_lp_get_home_tilde_collapsed)"
|
2013-11-30 17:54:01 -05:00
|
|
|
local mask="${LP_MARK_SHORTEN_PATH}"
|
2014-07-09 16:55:48 -04:00
|
|
|
local -i max_len=$(( ${COLUMNS:-80} * LP_PATH_LENGTH / 100 ))
|
2013-11-30 17:54:01 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_PATH_KEEP == -1 )); then
|
2013-11-30 17:54:01 -05:00
|
|
|
# only show the current directory, excluding any parent dirs
|
2014-06-27 19:57:24 -04:00
|
|
|
ret="${p##*/}" # discard everything up to and including the last slash
|
2013-11-30 17:54:01 -05:00
|
|
|
[[ "${ret}" == "" ]] && ret="/" # if in root directory
|
2014-07-09 16:55:48 -04:00
|
|
|
elif (( ${#p} <= max_len )); then
|
2013-11-30 17:54:01 -05:00
|
|
|
ret="${p}"
|
2016-07-18 16:22:07 -04:00
|
|
|
elif (( LP_PATH_KEEP == 0 )); then
|
2013-11-30 17:54:01 -05:00
|
|
|
# len is over max len, show as much of the tail as is allowed
|
2013-12-01 09:02:52 -05:00
|
|
|
ret="${p##*/}" # show at least complete current directory
|
2013-12-01 06:52:34 -05:00
|
|
|
p="${p:0:${#p} - ${#ret}}"
|
|
|
|
ret="${mask}${p:${#p} - (${max_len} - ${#ret} - ${#mask})}${ret}"
|
2013-11-30 17:54:01 -05:00
|
|
|
else
|
|
|
|
# len is over max len, show at least LP_PATH_KEEP leading dirs and
|
|
|
|
# current directory
|
2016-07-18 16:22:07 -04:00
|
|
|
local tmp="${p//\//}"
|
2013-11-30 17:54:01 -05:00
|
|
|
local -i delims=$(( ${#p} - ${#tmp} ))
|
|
|
|
|
2014-07-09 16:55:48 -04:00
|
|
|
for (( dir=0; dir < LP_PATH_KEEP; dir++ )); do
|
|
|
|
(( dir == delims )) && break
|
2013-11-30 17:54:01 -05:00
|
|
|
|
|
|
|
local left="${p#*/}"
|
|
|
|
local name="${p:0:${#p} - ${#left}}"
|
|
|
|
p="${left}"
|
2016-07-18 16:22:07 -04:00
|
|
|
ret+="${name%/}/"
|
2013-11-30 17:54:01 -05:00
|
|
|
done
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2014-07-09 16:55:48 -04:00
|
|
|
if (( delims <= LP_PATH_KEEP )); then
|
2013-11-30 17:54:01 -05:00
|
|
|
# no dirs between LP_PATH_KEEP leading dirs and current dir
|
2016-07-18 16:22:07 -04:00
|
|
|
ret+="${p##*/}"
|
2012-08-12 04:08:59 -04:00
|
|
|
else
|
2013-11-30 17:54:01 -05:00
|
|
|
local base="${p##*/}"
|
|
|
|
|
|
|
|
p="${p:0:${#p} - ${#base}}"
|
|
|
|
|
2013-12-01 07:02:59 -05:00
|
|
|
[[ ${ret} != "/" ]] && ret="${ret%/}" # strip trailing slash
|
2013-11-30 17:54:01 -05:00
|
|
|
|
2014-07-09 16:55:48 -04:00
|
|
|
local -i len_left=$(( max_len - ${#ret} - ${#base} - ${#mask} ))
|
2013-11-30 17:54:01 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
ret+="${mask}${p:${#p} - ${len_left}}${base}"
|
2012-08-12 04:51:29 -04:00
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
2014-01-03 03:32:08 -05:00
|
|
|
# Escape special chars
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_PWD="${LP_COLOR_PATH}$(_lp_escape "$ret")$NO_COL"
|
2012-07-29 16:19:06 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_ENABLE_SHORTEN_PATH )); then
|
|
|
|
if (( LP_PATH_KEEP == -1 )); then
|
|
|
|
# _lp_shorten_path becomes a noop
|
|
|
|
_lp_shorten_path()
|
|
|
|
{
|
|
|
|
:
|
|
|
|
}
|
|
|
|
# Will never change
|
|
|
|
LP_PWD="${LP_COLOR_PATH}${_LP_DIR_SYMBOL}$NO_COL"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Will never change
|
|
|
|
LP_PWD="${LP_COLOR_PATH}${LP_PATH_DEFAULT}$NO_COL"
|
|
|
|
|
|
|
|
if $_LP_SHELL_bash && [[ -n "$PROMPT_DIRTRIM" ]]; then
|
|
|
|
unset -f _lp_shorten_path
|
|
|
|
alias _lp_shorten_path=_lp_set_dirtrim
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# In Bash shells, PROMPT_DIRTRIM is the number of directories to keep at the end
|
2013-01-10 04:22:58 -05:00
|
|
|
# of the displayed path (if "\w" is present in the PS1 var).
|
2014-12-09 01:27:11 -05:00
|
|
|
# Liquid Prompt can calculate this number under two conditions, path shortening
|
2014-01-06 03:24:28 -05:00
|
|
|
# must be disabled and PROMPT_DIRTRIM must be already set.
|
2013-12-16 16:30:54 -05:00
|
|
|
_lp_set_dirtrim() {
|
2014-03-14 14:04:32 -04:00
|
|
|
local p="$(_lp_get_home_tilde_collapsed)"
|
2014-07-09 17:05:08 -04:00
|
|
|
local -i max_len="${COLUMNS:-80}*$LP_PATH_LENGTH/100"
|
2013-12-16 16:30:54 -05:00
|
|
|
local -i dt=0
|
|
|
|
|
|
|
|
if (( ${#p} > max_len )); then
|
|
|
|
local q="/${p##*/}"
|
|
|
|
local show="$q"
|
|
|
|
# +3 because of the ellipsis: "..."
|
2014-01-18 10:37:52 -05:00
|
|
|
while (( ${#show}+3 < max_len )); do
|
2013-12-16 16:30:54 -05:00
|
|
|
(( dt++ ))
|
|
|
|
p="${p%$q}"
|
|
|
|
q="/${p##*/}"
|
|
|
|
show="$q$show"
|
2013-01-09 07:50:06 -05:00
|
|
|
done
|
2013-12-16 16:30:54 -05:00
|
|
|
(( dt == 0 )) && dt=1
|
2013-01-09 07:50:06 -05:00
|
|
|
fi
|
2013-12-16 16:30:54 -05:00
|
|
|
PROMPT_DIRTRIM=$dt
|
|
|
|
# For debugging
|
2013-12-16 18:12:14 -05:00
|
|
|
# echo PROMPT_DIRTRIM=$PROMPT_DIRTRIM >&2
|
2013-01-09 07:50:06 -05:00
|
|
|
}
|
|
|
|
|
2013-01-03 10:44:15 -05:00
|
|
|
|
2012-07-22 16:28:50 -04:00
|
|
|
|
2012-07-19 05:21:18 -04:00
|
|
|
################
|
|
|
|
# Related jobs #
|
|
|
|
################
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2013-03-14 17:41:09 -04:00
|
|
|
# Display the count of each if non-zero:
|
|
|
|
# - detached screens sessions and/or tmux sessions running on the host
|
|
|
|
# - attached running jobs (started with $ myjob &)
|
|
|
|
# - attached stopped jobs (suspended with Ctrl-Z)
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_jobcount_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_JOBS )) || return
|
2012-08-16 12:35:07 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
local ret=""
|
|
|
|
local -i r s
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Count detached sessions
|
|
|
|
if (( _LP_ENABLE_DETACHED_SESSIONS )); then
|
2014-06-27 15:45:11 -04:00
|
|
|
local -i detached=0
|
2016-07-18 16:22:07 -04:00
|
|
|
(( _LP_ENABLE_SCREEN )) && detached=$(screen -ls 2> /dev/null | \grep -c '[Dd]etach[^)]*)$')
|
|
|
|
(( _LP_ENABLE_TMUX )) && detached+=$(tmux list-sessions 2> /dev/null | \grep -cv 'attached')
|
|
|
|
(( detached > 0 )) && ret+="${LP_COLOR_JOB_D}${detached}d${NO_COL}"
|
2013-03-14 17:41:09 -04:00
|
|
|
fi
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Count running jobs
|
|
|
|
if (( r = $(jobs -r | wc -l) )); then
|
|
|
|
[[ -n "$ret" ]] && ret+='/'
|
|
|
|
ret+="${LP_COLOR_JOB_R}${r}&${NO_COL}"
|
2013-03-14 17:41:09 -04:00
|
|
|
fi
|
2012-08-10 09:08:08 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Count stopped jobs
|
|
|
|
if (( s = $(jobs -s | wc -l) )); then
|
|
|
|
[[ -n "$ret" ]] && ret+='/'
|
|
|
|
ret+="${LP_COLOR_JOB_Z}${s}z${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2013-03-14 17:41:09 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "$ret"
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2013-02-26 08:18:58 -05:00
|
|
|
|
2012-07-19 03:59:09 -04:00
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
######################
|
2012-07-19 03:59:09 -04:00
|
|
|
# VCS branch display #
|
2012-07-07 03:32:29 -04:00
|
|
|
######################
|
|
|
|
|
2013-05-16 16:31:34 -04:00
|
|
|
_lp_are_vcs_enabled()
|
2013-01-23 07:36:29 -05:00
|
|
|
{
|
2013-05-16 16:31:34 -04:00
|
|
|
[[ -z "$LP_DISABLED_VCS_PATH" ]] && return 0
|
2016-07-18 16:22:07 -04:00
|
|
|
$_LP_SHELL_zsh && setopt local_options && setopt sh_word_split
|
2013-01-23 07:36:29 -05:00
|
|
|
local path
|
|
|
|
local IFS=:
|
|
|
|
for path in $LP_DISABLED_VCS_PATH; do
|
2013-05-16 16:31:34 -04:00
|
|
|
[[ "$PWD" == *"$path"* ]] && return 1
|
2013-01-23 07:36:29 -05:00
|
|
|
done
|
2013-05-16 16:31:34 -04:00
|
|
|
return 0
|
2013-01-23 07:36:29 -05:00
|
|
|
}
|
|
|
|
|
2012-07-19 03:59:09 -04:00
|
|
|
# GIT #
|
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
# Get the branch name of the current directory
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_git_branch()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_GIT )) || return
|
2014-06-27 18:27:47 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
\git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return
|
2014-06-27 18:27:47 -04:00
|
|
|
|
2013-08-20 14:09:26 -04:00
|
|
|
local branch
|
|
|
|
# Recent versions of Git support the --short option for symbolic-ref, but
|
|
|
|
# not 1.7.9 (Ubuntu 12.04)
|
|
|
|
if branch="$(\git symbolic-ref -q HEAD)"; then
|
|
|
|
_lp_escape "${branch#refs/heads/}"
|
|
|
|
else
|
2013-03-12 15:47:52 -04:00
|
|
|
# In detached head state, use commit instead
|
2013-05-16 13:12:42 -04:00
|
|
|
# No escape needed
|
2013-08-20 14:09:26 -04:00
|
|
|
\git rev-parse --short -q HEAD
|
2013-03-12 15:47:52 -04:00
|
|
|
fi
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
|
|
|
|
# Display additional information if HEAD is in merging, rebasing
|
|
|
|
# or cherry-picking state
|
|
|
|
_lp_git_head_status() {
|
|
|
|
local gitdir
|
|
|
|
gitdir="$(\git rev-parse --git-dir 2>/dev/null)"
|
|
|
|
if [[ -f "${gitdir}/MERGE_HEAD" ]]; then
|
|
|
|
echo " MERGING"
|
|
|
|
elif [[ -d "${gitdir}/rebase-apply" || -d "${gitdir}/rebase-merge" ]]; then
|
|
|
|
echo " REBASING"
|
|
|
|
elif [[ -f "${gitdir}/CHERRY_PICK_HEAD" ]]; then
|
|
|
|
echo " CHERRY-PICKING"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
# Set a color depending on the branch state:
|
|
|
|
# - green if the repository is up to date
|
|
|
|
# - yellow if there is some commits not pushed
|
|
|
|
# - red if there is changes to commit
|
2012-08-04 13:52:24 -04:00
|
|
|
#
|
|
|
|
# Add the number of pending commits and the impacted lines.
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_git_branch_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_GIT )) || return
|
2012-08-16 12:35:07 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(_lp_git_branch)"
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$branch" ]]; then
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2013-09-18 04:56:36 -04:00
|
|
|
local end
|
2016-07-18 16:22:07 -04:00
|
|
|
end="${LP_COLOR_CHANGES}$(_lp_git_head_status)${NO_COL}"
|
|
|
|
|
2015-01-05 17:32:23 -05:00
|
|
|
if LC_ALL=C \git status --porcelain 2>/dev/null | \grep -Eq '^\?\?'; then
|
2013-04-24 09:21:58 -04:00
|
|
|
end="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED$end"
|
2012-08-16 08:08:07 -04:00
|
|
|
fi
|
|
|
|
|
2014-01-20 15:02:41 -05:00
|
|
|
if [[ -n "$(\git stash list -n 1 2>/dev/null)" ]]; then
|
2013-04-24 09:21:58 -04:00
|
|
|
end="$LP_COLOR_COMMITS$LP_MARK_STASH$end"
|
2013-01-17 17:02:17 -05:00
|
|
|
fi
|
|
|
|
|
2013-03-12 15:51:22 -04:00
|
|
|
local remote
|
2013-07-26 04:30:50 -04:00
|
|
|
remote="$(\git config --get branch.${branch}.remote 2>/dev/null)"
|
2013-03-12 15:51:22 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
local has_commit=""
|
|
|
|
local commit_ahead
|
|
|
|
local commit_behind
|
2014-03-08 16:38:50 -05:00
|
|
|
if [[ -n "$remote" ]]; then
|
2013-04-24 09:21:58 -04:00
|
|
|
local remote_branch
|
2013-07-26 04:30:50 -04:00
|
|
|
remote_branch="$(\git config --get branch.${branch}.merge)"
|
2014-03-08 16:38:50 -05:00
|
|
|
if [[ -n "$remote_branch" ]]; then
|
2016-07-18 16:22:07 -04:00
|
|
|
remote_branch=${remote_branch/refs\/heads/refs\/remotes\/$remote}
|
|
|
|
commit_ahead="$(\git rev-list --count $remote_branch..HEAD 2>/dev/null)"
|
|
|
|
commit_behind="$(\git rev-list --count HEAD..$remote_branch 2>/dev/null)"
|
|
|
|
if [[ "$commit_ahead" -ne "0" && "$commit_behind" -ne "0" ]]; then
|
|
|
|
has_commit="${LP_COLOR_COMMITS}+$commit_ahead${NO_COL}/${LP_COLOR_COMMITS_BEHIND}-$commit_behind${NO_COL}"
|
|
|
|
elif [[ "$commit_ahead" -ne "0" ]]; then
|
|
|
|
has_commit="${LP_COLOR_COMMITS}$commit_ahead${NO_COL}"
|
|
|
|
elif [[ "$commit_behind" -ne "0" ]]; then
|
|
|
|
has_commit="${LP_COLOR_COMMITS_BEHIND}-$commit_behind${NO_COL}"
|
|
|
|
fi
|
2013-03-12 15:51:22 -04:00
|
|
|
fi
|
2012-07-19 04:49:07 -04:00
|
|
|
fi
|
2013-05-14 18:33:28 -04:00
|
|
|
|
2013-11-27 18:21:20 -05:00
|
|
|
local ret
|
2013-12-11 11:20:52 -05:00
|
|
|
local shortstat # only to check for uncommitted changes
|
2013-09-24 16:40:19 -04:00
|
|
|
shortstat="$(LC_ALL=C \git diff --shortstat HEAD 2>/dev/null)"
|
2013-12-11 11:20:52 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$shortstat" ]]; then
|
2013-12-11 11:20:52 -05:00
|
|
|
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
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$u_stat" = *insertion* ]]; then
|
2013-12-11 11:20:52 -05:00
|
|
|
i_lines=${u_stat/ inser*}
|
|
|
|
else
|
|
|
|
i_lines=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local d_lines # deleted lines
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$u_stat" = *deletion* ]]; then
|
2013-12-11 11:20:52 -05:00
|
|
|
d_lines=${u_stat/*\(+\), }
|
|
|
|
d_lines=${d_lines/ del*/}
|
|
|
|
else
|
|
|
|
d_lines=0
|
|
|
|
fi
|
|
|
|
|
2013-09-18 04:56:36 -04:00
|
|
|
local has_lines
|
2013-12-11 11:20:52 -05:00
|
|
|
has_lines="+$i_lines/-$d_lines"
|
2013-05-14 18:33:28 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$has_commit" ]]; then
|
2012-08-04 13:52:24 -04:00
|
|
|
# Changes to commit and commits to push
|
2016-07-18 16:22:07 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},$has_commit)"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2013-05-14 18:28:32 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})" # changes to commit
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
elif [[ -n "$has_commit" ]]; then
|
|
|
|
# some commit(s) to push
|
|
|
|
if [[ "$commit_behind" -gt "0" ]]; then
|
|
|
|
ret="${LP_COLOR_COMMITS_BEHIND}${branch}${NO_COL}($has_commit)"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}($has_commit)"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
else
|
|
|
|
ret="${LP_COLOR_UP}${branch}" # nothing to commit or push
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "$ret$end"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2013-10-18 22:19:43 -04:00
|
|
|
# Search upwards through a directory structure looking for a file/folder with
|
|
|
|
# the given name. Used to avoid invoking 'hg' and 'bzr'.
|
2013-10-18 22:03:42 -04:00
|
|
|
_lp_upwards_find()
|
|
|
|
{
|
2013-12-30 13:37:32 -05:00
|
|
|
local dir
|
|
|
|
dir="$PWD"
|
2014-01-18 10:37:52 -05:00
|
|
|
while [[ -n "$dir" ]]; do
|
2013-12-30 13:37:32 -05:00
|
|
|
[[ -d "$dir/$1" ]] && return 0
|
|
|
|
dir="${dir%/*}"
|
2013-10-18 22:03:42 -04:00
|
|
|
done
|
2013-12-30 13:37:32 -05:00
|
|
|
return 1
|
2013-10-18 22:03:42 -04:00
|
|
|
}
|
|
|
|
|
2012-07-19 03:59:09 -04:00
|
|
|
# MERCURIAL #
|
|
|
|
|
|
|
|
# Get the branch name of the current directory
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_hg_branch()
|
2012-07-19 03:59:09 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_HG )) || return
|
2013-12-04 16:51:48 -05:00
|
|
|
|
2013-10-18 22:03:42 -04:00
|
|
|
# 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.
|
2013-12-30 13:37:32 -05:00
|
|
|
_lp_upwards_find .hg || return
|
2013-10-18 22:03:42 -04:00
|
|
|
|
|
|
|
# We found an .hg folder, so we need to invoke hg and see if we're actually
|
|
|
|
# in a repository.
|
2013-12-04 16:51:48 -05:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local branch
|
2012-07-19 03:59:09 -04:00
|
|
|
branch="$(hg branch 2>/dev/null)"
|
2013-03-13 10:58:56 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
(( $? == 0 )) && _lp_escape "$branch"
|
2012-07-19 03:59:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Set a color depending on the branch state:
|
|
|
|
# - green if the repository is up to date
|
|
|
|
# - red if there is changes to commit
|
|
|
|
# - TODO: yellow if there is some commits not pushed
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_hg_branch_color()
|
2012-07-19 03:59:09 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_HG )) || return
|
2012-08-16 12:35:07 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local branch
|
|
|
|
local ret
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(_lp_hg_branch)"
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$branch" ]]; then
|
2013-03-13 13:31:26 -04:00
|
|
|
|
|
|
|
local has_untracked
|
2014-01-19 09:05:30 -05:00
|
|
|
has_untracked=
|
2015-01-05 17:32:23 -05:00
|
|
|
if hg status -u 2>/dev/null | \grep -q '^\?' >/dev/null ; then
|
2013-03-13 13:31:26 -04:00
|
|
|
has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED"
|
|
|
|
fi
|
|
|
|
|
2014-01-19 09:15:52 -05:00
|
|
|
# Count local commits waiting for a push
|
2014-01-24 16:24:16 -05:00
|
|
|
#
|
|
|
|
# Unfortunately this requires contacting the remote, so this is always slow
|
|
|
|
# => disabled https://github.com/nojhan/liquidprompt/issues/217
|
2014-01-19 09:15:52 -05:00
|
|
|
local -i commits
|
2015-01-05 17:32:23 -05:00
|
|
|
#commits=$(hg outgoing --no-merges ${branch} 2>/dev/null | \grep -c '\(^changeset\:\)')
|
2014-01-24 16:24:16 -05:00
|
|
|
commits=0
|
2013-03-13 13:31:26 -04:00
|
|
|
|
2014-01-19 10:02:26 -05:00
|
|
|
# Check if there is some uncommitted stuff
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -z "$(hg status --quiet -n)" ]]; then
|
|
|
|
if (( commits > 0 )); then
|
2013-03-13 13:31:26 -04:00
|
|
|
# some commit(s) to push
|
2014-01-19 09:15:52 -05:00
|
|
|
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$commits${NO_COL})${has_untracked}${NO_COL}"
|
2013-03-13 13:31:26 -04:00
|
|
|
else
|
2014-01-19 10:03:28 -05:00
|
|
|
# nothing to commit or push
|
|
|
|
ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}"
|
2013-03-13 13:31:26 -04:00
|
|
|
fi
|
2012-07-19 03:59:09 -04:00
|
|
|
else
|
2013-11-25 16:37:09 -05:00
|
|
|
local has_lines
|
2014-01-19 13:56:00 -05:00
|
|
|
# Parse the last line of the diffstat-style output
|
|
|
|
has_lines="$(hg diff --stat 2>/dev/null | sed -n '$ s!^.*, \([0-9]*\) .*, \([0-9]*\).*$!+\1/-\2!p')"
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( commits > 0 )); then
|
2013-03-13 13:31:26 -04:00
|
|
|
# Changes to commit and commits to push
|
2014-01-19 09:15:52 -05:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$commits${NO_COL})${has_untracked}${NO_COL}"
|
2013-03-13 13:31:26 -04:00
|
|
|
else
|
2013-03-25 15:57:46 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit
|
2013-03-13 13:31:26 -04:00
|
|
|
fi
|
2012-07-19 03:59:09 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "$ret"
|
2012-07-19 03:59:09 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-07-19 04:49:07 -04:00
|
|
|
# SUBVERSION #
|
|
|
|
|
2012-07-19 05:00:18 -04:00
|
|
|
# Get the branch name of the current directory
|
|
|
|
# For the first level of the repository, gives the repository name
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_svn_branch()
|
2012-07-19 04:49:07 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_SVN )) || return
|
|
|
|
|
|
|
|
local root=
|
|
|
|
local url=
|
2014-07-09 17:07:19 -04:00
|
|
|
eval "$(LANG=C LC_ALL=C svn info 2>/dev/null | sed -n 's/^URL: \(.*\)/url="\1"/p;s/^Repository Root: \(.*\)/root="\1"/p' )"
|
2016-07-18 16:22:07 -04:00
|
|
|
[[ -z "${root-}" ]] && return
|
2013-05-22 17:42:55 -04:00
|
|
|
|
2012-08-17 02:32:00 -04:00
|
|
|
# Make url relative to root
|
|
|
|
url="${url:${#root}}"
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$url" == */trunk* ]]; then
|
2013-03-13 17:49:23 -04:00
|
|
|
echo -n trunk
|
2016-07-18 16:22:07 -04:00
|
|
|
elif [[ "$url" == */branches/?* ]]; then
|
2014-06-28 16:27:32 -04:00
|
|
|
url="${url##*/branches/}"
|
|
|
|
_lp_escape "${url%/*}"
|
2016-07-18 16:22:07 -04:00
|
|
|
elif [[ "$url" == */tags/?* ]]; then
|
2014-06-28 16:27:32 -04:00
|
|
|
url="${url##*/tags/}"
|
|
|
|
_lp_escape "${url%/*}"
|
2014-03-18 20:18:23 -04:00
|
|
|
else
|
2014-06-28 16:27:32 -04:00
|
|
|
_lp_escape "${root##*/}"
|
2012-07-19 04:49:07 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-07-19 05:00:18 -04:00
|
|
|
# Set a color depending on the branch state:
|
2012-08-17 03:52:28 -04:00
|
|
|
# - green if the repository is clean
|
2016-07-18 16:22:07 -04:00
|
|
|
# (use $LP_SVN_STATUS_OPTIONS to define what that means with
|
2012-08-17 03:52:28 -04:00
|
|
|
# the --depth option of 'svn status')
|
2012-07-19 05:00:18 -04:00
|
|
|
# - red if there is changes to commit
|
|
|
|
# Note that, due to subversion way of managing changes,
|
|
|
|
# informations are only displayed for the CURRENT directory.
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_svn_branch_color()
|
2012-07-19 04:49:07 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_SVN )) || return
|
2012-08-16 12:35:07 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local branch
|
2012-08-17 03:52:28 -04:00
|
|
|
branch="$(_lp_svn_branch)"
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$branch" ]]; then
|
2014-01-20 14:44:43 -05:00
|
|
|
local changes
|
2016-07-18 16:22:07 -04:00
|
|
|
changes=$(( $(svn status ${LP_SVN_STATUS_OPTIONS-} | \grep -c -v "?") ))
|
|
|
|
if (( changes == 0 )); then
|
|
|
|
echo -nE "${LP_COLOR_UP}${branch}${NO_COL}"
|
2012-07-19 04:49:07 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$changes${NO_COL})" # changes to commit
|
2012-07-19 04:49:07 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-28 20:42:29 -05:00
|
|
|
# FOSSIL #
|
|
|
|
|
|
|
|
# Get the tag name of the current directory
|
|
|
|
_lp_fossil_branch()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_FOSSIL )) || return
|
2013-01-12 10:29:55 -05:00
|
|
|
local branch
|
2016-07-18 16:22:07 -04:00
|
|
|
branch=$(fossil status 2>/dev/null | sed -n -$_LP_SED_EXTENDED 's/^tags:\s+(\w*)$/\1/p')
|
|
|
|
if [[ -n "$branch" ]]; then
|
|
|
|
echo -nE "$branch"
|
|
|
|
elif fossil info &>/dev/null ; then
|
|
|
|
echo -n "no-tag"
|
2012-12-29 08:40:54 -05:00
|
|
|
fi
|
2012-12-28 20:42:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Set a color depending on the branch state:
|
|
|
|
# - green if the repository is clean
|
|
|
|
# - red if there is changes to commit
|
2013-01-05 17:03:26 -05:00
|
|
|
# - yellow if the branch has no tag name
|
2012-12-29 08:40:54 -05:00
|
|
|
#
|
|
|
|
# Add the number of impacted files with a
|
|
|
|
# + when files are ADDED or EDITED
|
|
|
|
# - when files are DELETED
|
2012-12-28 20:42:29 -05:00
|
|
|
_lp_fossil_branch_color()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_FOSSIL )) || return
|
2012-12-28 20:42:29 -05:00
|
|
|
|
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(_lp_fossil_branch)"
|
2012-12-29 08:40:54 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$branch" ]]; then
|
2014-02-14 12:28:54 -05:00
|
|
|
local -i C2E # Modified files (added or edited)
|
2013-03-13 10:58:56 -04:00
|
|
|
local C2A # Extras files
|
|
|
|
local ret
|
|
|
|
C2E=$(fossil changes | wc -l)
|
|
|
|
C2A=$(fossil extras | wc -l)
|
2014-02-20 15:35:57 -05:00
|
|
|
ret=$(fossil diff -i -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}")
|
2013-12-04 16:54:03 -05:00
|
|
|
|
2014-02-14 12:28:54 -05:00
|
|
|
if (( C2E > 0 )); then
|
2014-02-20 15:09:42 -05:00
|
|
|
[[ -n "$ret" ]] && ret+=" in "
|
|
|
|
ret="(${LP_COLOR_DIFF}${ret}${C2E}${NO_COL})"
|
2013-12-04 16:54:03 -05:00
|
|
|
fi
|
|
|
|
|
2014-07-09 17:09:14 -04:00
|
|
|
if (( C2A > 0 )); then
|
2014-02-01 09:52:13 -05:00
|
|
|
C2A="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED"
|
2013-03-13 10:58:56 -04:00
|
|
|
else
|
|
|
|
C2A=""
|
|
|
|
fi
|
|
|
|
|
2014-02-14 12:28:54 -05:00
|
|
|
if [[ "$branch" = "no-tag" ]]; then
|
2013-01-05 17:03:26 -05:00
|
|
|
# Warning, your branch has no tag name !
|
2013-03-13 10:58:56 -04:00
|
|
|
branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}"
|
2016-07-18 16:22:07 -04:00
|
|
|
elif (( C2E == 0 )); then
|
|
|
|
# All is up-to-date
|
|
|
|
branch="${LP_COLOR_UP}$branch$C2A${NO_COL}"
|
2013-03-13 10:58:56 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
# There're some changes to commit
|
|
|
|
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
|
2013-03-13 10:58:56 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "$branch"
|
2012-12-28 20:42:29 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-01-17 11:20:15 -05:00
|
|
|
# Bazaar #
|
|
|
|
|
|
|
|
# Get the branch name of the current directory
|
|
|
|
_lp_bzr_branch()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_BZR )) || return
|
2013-10-18 22:03:42 -04:00
|
|
|
|
|
|
|
# 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.
|
2013-12-30 13:37:32 -05:00
|
|
|
_lp_upwards_find .bzr || return
|
2013-10-18 22:03:42 -04:00
|
|
|
|
|
|
|
# We found an .bzr folder, so we need to invoke bzr and see if we're
|
|
|
|
# actually in a repository.
|
|
|
|
|
2013-03-13 10:58:56 -04:00
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(bzr nick 2> /dev/null)"
|
2016-07-18 16:22:07 -04:00
|
|
|
(( $? != 0 )) && return
|
2013-05-16 13:41:25 -04:00
|
|
|
_lp_escape "$branch"
|
2013-01-17 11:20:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Set a color depending on the branch state:
|
|
|
|
# - green if the repository is up to date
|
|
|
|
# - red if there is changes to commit
|
|
|
|
# - TODO: yellow if there is some commits not pushed
|
|
|
|
#
|
|
|
|
# Add the number of pending commits and the impacted lines.
|
|
|
|
_lp_bzr_branch_color()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_BZR )) || return
|
2013-10-18 22:03:42 -04:00
|
|
|
|
|
|
|
# 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.
|
2013-12-30 13:37:32 -05:00
|
|
|
_lp_upwards_find .bzr || return
|
2013-10-18 22:03:42 -04:00
|
|
|
|
|
|
|
# We found an .bzr folder, so we need to invoke bzr and see if we're
|
|
|
|
# actually in a repository.
|
|
|
|
|
2013-03-12 15:00:36 -04:00
|
|
|
local output
|
2013-06-02 06:14:58 -04:00
|
|
|
output="$(bzr version-info --check-clean --custom --template='{branch_nick} {revno} {clean}' 2> /dev/null)"
|
2016-07-18 16:22:07 -04:00
|
|
|
(( $? != 0 )) && return
|
2014-06-03 14:53:42 -04:00
|
|
|
$_LP_SHELL_zsh && setopt local_options && setopt sh_word_split
|
|
|
|
local tuple
|
|
|
|
tuple=($output)
|
|
|
|
$_LP_SHELL_zsh && unsetopt sh_word_split
|
2013-06-02 05:02:34 -04:00
|
|
|
local branch=${tuple[_LP_FIRST_INDEX+0]}
|
|
|
|
local revno=${tuple[_LP_FIRST_INDEX+1]}
|
|
|
|
local clean=${tuple[_LP_FIRST_INDEX+2]}
|
2016-07-18 16:22:07 -04:00
|
|
|
local ret=
|
2013-01-17 11:20:15 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "$branch" ]]; then
|
|
|
|
if (( clean == 0 )); then
|
2013-01-17 11:20:15 -05:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})"
|
|
|
|
else
|
2013-03-13 10:58:56 -04:00
|
|
|
ret="${LP_COLOR_UP}${branch}${NO_COL}(${LP_COLOR_COMMITS}$revno${NO_COL})"
|
2013-01-17 11:20:15 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "$ret"
|
2013-01-17 11:20:15 -05:00
|
|
|
}
|
|
|
|
|
2012-12-28 20:42:29 -05:00
|
|
|
|
2013-12-05 18:38:51 -05:00
|
|
|
####################
|
|
|
|
# Wifi link status #
|
|
|
|
####################
|
|
|
|
_lp_wifi()
|
|
|
|
{
|
|
|
|
# Linux
|
|
|
|
sed -n '3s/^ *[^ ]* *[^ ]* *\([0-9]*\).*/\1/p' /proc/net/wireless
|
|
|
|
}
|
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
##################
|
|
|
|
# Battery status #
|
|
|
|
##################
|
|
|
|
|
|
|
|
# Get the battery status in percent
|
2012-08-12 06:13:47 -04:00
|
|
|
# returns 0 (and battery level) if battery is discharging and under threshold
|
|
|
|
# returns 1 (and battery level) if battery is discharging and above threshold
|
|
|
|
# returns 2 (and battery level) if battery is charging but under threshold
|
|
|
|
# returns 3 (and battery level) if battery is charging and above threshold
|
|
|
|
# returns 4 if no battery support
|
2013-05-14 19:04:26 -04:00
|
|
|
case "$LP_OS" in
|
|
|
|
Linux)
|
|
|
|
_lp_battery()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_BATT )) || return 4
|
|
|
|
local acpi
|
|
|
|
acpi="$(acpi --battery 2>/dev/null)"
|
|
|
|
# Extract the battery load value in percent
|
|
|
|
# First, remove the beginning of the line...
|
|
|
|
local bat="${acpi#Battery *, }"
|
|
|
|
bat="${bat%%%*}" # remove everything starting at '%'
|
|
|
|
|
|
|
|
if [[ -z "${bat}" ]]; then
|
|
|
|
# no battery level found
|
2013-05-14 19:04:26 -04:00
|
|
|
return 4
|
2016-07-18 16:22:07 -04:00
|
|
|
fi
|
|
|
|
echo -nE "$bat"
|
2013-05-14 19:04:26 -04:00
|
|
|
# discharging
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$acpi" == *"Discharging"* ]]; then
|
|
|
|
# under => 0, above => 1
|
|
|
|
return $(( bat > LP_BATTERY_THRESHOLD ))
|
2013-05-14 19:04:26 -04:00
|
|
|
# charging
|
2012-08-12 06:13:47 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
# under => 2, above => 3
|
|
|
|
return $(( 1 + ( bat > LP_BATTERY_THRESHOLD ) ))
|
2012-08-12 06:13:47 -04:00
|
|
|
fi
|
2013-05-14 19:04:26 -04:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
Darwin)
|
|
|
|
_lp_battery()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_BATT )) || return 4
|
|
|
|
local percent batt_status
|
|
|
|
eval "$(pmset -g batt | sed -n 's/^ -InternalBattery[^ ]*[ ]\([0-9]*[0-9]\)%; \([^;]*\).*$/percent=\1 batt_status='\'\\2\'/p)"
|
|
|
|
case "$batt_status" in
|
|
|
|
charged | "")
|
2013-06-11 22:02:41 -04:00
|
|
|
return 4
|
|
|
|
;;
|
2016-07-18 16:22:07 -04:00
|
|
|
discharging)
|
|
|
|
echo -nE "$percent"
|
|
|
|
# under => 0, above => 1
|
|
|
|
return $(( percent > LP_BATTERY_THRESHOLD ))
|
2013-06-11 22:02:41 -04:00
|
|
|
;;
|
2016-07-18 16:22:07 -04:00
|
|
|
*) # "charging", "AC attached"
|
|
|
|
echo -nE "$percent"
|
|
|
|
# under => 2, above => 3
|
|
|
|
return $(( 1 + ( percent > LP_BATTERY_THRESHOLD ) ))
|
2013-06-11 22:02:41 -04:00
|
|
|
;;
|
|
|
|
esac
|
2013-05-14 19:04:26 -04:00
|
|
|
}
|
|
|
|
;;
|
|
|
|
esac
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-17 03:22:40 -04:00
|
|
|
# Compute a gradient of background/foreground colors depending on the battery status
|
2012-08-12 06:13:47 -04:00
|
|
|
# Display:
|
2012-08-13 16:09:49 -04:00
|
|
|
# a green ⏚ if the battery is charging and above threshold
|
|
|
|
# a yellow ⏚ if the battery is charging and under threshold
|
|
|
|
# a yellow ⌁ if the battery is discharging but above threshold
|
|
|
|
# a red ⌁ if the battery is discharging and above threshold
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_battery_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_BATT )) || return
|
2012-08-16 12:35:07 -04:00
|
|
|
|
2012-08-17 12:10:11 -04:00
|
|
|
local mark=$LP_MARK_BATTERY
|
|
|
|
local chargingmark=$LP_MARK_ADAPTER
|
2016-07-18 16:22:07 -04:00
|
|
|
local -i bat ret
|
2013-06-02 06:14:58 -04:00
|
|
|
bat="$(_lp_battery)"
|
2012-08-12 06:13:47 -04:00
|
|
|
ret=$?
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( ret == 4 || bat == 100 )); then
|
2012-08-12 06:13:47 -04:00
|
|
|
# no battery support or battery full: nothing displayed
|
2016-07-18 16:22:07 -04:00
|
|
|
:
|
|
|
|
elif (( ret == 3 && bat != 100 )); then
|
2012-08-12 06:13:47 -04:00
|
|
|
# charging and above threshold and not 100%
|
2012-08-13 04:02:10 -04:00
|
|
|
# green ⏚
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${LP_COLOR_CHARGING_ABOVE}$chargingmark${NO_COL}"
|
|
|
|
elif (( ret == 2 )); then
|
2012-08-12 06:13:47 -04:00
|
|
|
# charging but under threshold
|
2012-08-13 04:02:10 -04:00
|
|
|
# yellow ⏚
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${LP_COLOR_CHARGING_UNDER}$chargingmark${NO_COL}"
|
|
|
|
elif (( ret == 1 )); then
|
2012-08-12 06:13:47 -04:00
|
|
|
# discharging but above threshold
|
2012-08-13 04:02:10 -04:00
|
|
|
# yellow ⌁
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${LP_COLOR_DISCHARGING_ABOVE}$mark${NO_COL}"
|
2012-08-12 06:13:47 -04:00
|
|
|
# discharging and under threshold
|
2016-07-18 16:22:07 -04:00
|
|
|
else
|
|
|
|
local res
|
|
|
|
res="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_PERCENTS_ALWAYS )); then
|
|
|
|
local -i idx
|
2014-06-30 17:56:49 -04:00
|
|
|
if (( bat <= 0 )); then
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=0
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 5 )); then # 5
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=9
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 10 )); then # 5
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=8
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 20 )); then # 10
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=7
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 30 )); then # 10
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=6
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 40 )); then # 10
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=5
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 50 )); then # 10
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=4
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 65 )); then # 15
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=3
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat <= 80 )); then # 15
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=2
|
2014-06-30 17:56:49 -04:00
|
|
|
elif (( bat < 100 )); then # 20
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=1
|
2014-06-30 17:56:49 -04:00
|
|
|
else # >= 100
|
2016-07-18 16:22:07 -04:00
|
|
|
idx=0
|
2013-03-13 07:30:41 -04:00
|
|
|
fi
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
res+="${LP_COLORMAP[idx+_LP_FIRST_INDEX]}${bat}$_LP_PERCENT${NO_COL}"
|
2013-03-13 07:30:41 -04:00
|
|
|
fi # LP_PERCENTS_ALWAYS
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${res}"
|
|
|
|
fi
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:16:06 -04:00
|
|
|
_lp_color_map() {
|
2013-06-11 15:03:10 -04:00
|
|
|
# Default scale: 0..100
|
|
|
|
# Custom scale: 0..$2
|
2016-07-18 16:22:07 -04:00
|
|
|
local -i scale idx
|
2013-06-12 09:21:11 -04:00
|
|
|
scale=${2:-100}
|
2016-07-18 16:22:07 -04:00
|
|
|
# Transform the value to a 0..${#COLOR_MAP} scale
|
|
|
|
idx=_LP_FIRST_INDEX+100*$1/scale/${#LP_COLORMAP[*]}
|
|
|
|
echo -nE "${LP_COLORMAP[idx]}"
|
2013-04-21 10:16:06 -04:00
|
|
|
}
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2013-06-11 13:32:02 -04:00
|
|
|
###########################
|
|
|
|
# runtime of last command #
|
|
|
|
###########################
|
|
|
|
|
2013-08-01 02:23:42 -04:00
|
|
|
_LP_RUNTIME_LAST_SECONDS=$SECONDS
|
2013-06-11 13:32:02 -04:00
|
|
|
|
|
|
|
_lp_runtime()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_ENABLE_RUNTIME && _LP_RUNTIME_SECONDS >= LP_RUNTIME_THRESHOLD ))
|
2013-06-11 13:32:02 -04:00
|
|
|
then
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${LP_COLOR_RUNTIME}"
|
2013-06-11 13:32:02 -04:00
|
|
|
# display runtime seconds as days, hours, minutes, and seconds
|
2016-07-18 16:22:07 -04:00
|
|
|
(( _LP_RUNTIME_SECONDS >= 86400 )) && echo -n $((_LP_RUNTIME_SECONDS / 86400))d
|
|
|
|
(( _LP_RUNTIME_SECONDS >= 3600 )) && echo -n $((_LP_RUNTIME_SECONDS % 86400 / 3600))h
|
|
|
|
(( _LP_RUNTIME_SECONDS >= 60 )) && echo -n $((_LP_RUNTIME_SECONDS % 3600 / 60))m
|
|
|
|
echo -n $((_LP_RUNTIME_SECONDS % 60))"s${NO_COL}"
|
2013-06-11 13:32:02 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
:
|
2013-06-11 13:32:02 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_ENABLE_RUNTIME )); then
|
|
|
|
if $_LP_SHELL_zsh; then
|
|
|
|
_lp_runtime_before() {
|
|
|
|
_LP_RUNTIME_LAST_SECONDS=$SECONDS
|
|
|
|
}
|
|
|
|
_lp_runtime_after() {
|
|
|
|
if [[ -n "$_LP_RUNTIME_LAST_SECONDS" ]]; then
|
|
|
|
(( _LP_RUNTIME_SECONDS=SECONDS-_LP_RUNTIME_LAST_SECONDS ))
|
|
|
|
unset _LP_RUNTIME_LAST_SECONDS
|
|
|
|
fi
|
|
|
|
}
|
2015-03-29 00:41:44 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
add-zsh-hook preexec _lp_runtime_before
|
|
|
|
add-zsh-hook precmd _lp_runtime_after
|
|
|
|
else
|
|
|
|
_lp_runtime_before()
|
|
|
|
{
|
|
|
|
# For debugging
|
|
|
|
#echo "XXX $BASH_COMMAND"
|
|
|
|
|
|
|
|
# If the previous command was just the refresh of the prompt,
|
|
|
|
# reset the counter
|
|
|
|
if (( _LP_RUNTIME_SKIP )); then
|
|
|
|
_LP_RUNTIME_SECONDS=-1 _LP_RUNTIME_LAST_SECONDS=$SECONDS
|
|
|
|
else
|
|
|
|
# Compute number of seconds since program was started
|
|
|
|
(( _LP_RUNTIME_SECONDS=SECONDS-_LP_RUNTIME_LAST_SECONDS ))
|
|
|
|
fi
|
2013-06-11 13:32:02 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# If the command to run is the prompt, we'll have to ignore it
|
|
|
|
[[ "$BASH_COMMAND" != "$PROMPT_COMMAND" ]]
|
|
|
|
_LP_RUNTIME_SKIP=$?
|
2015-04-01 07:08:31 -04:00
|
|
|
}
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_RUNTIME_SKIP=0
|
|
|
|
# _lp_runtime_before gets called just before bash executes a command,
|
|
|
|
# including $PROMPT_COMMAND
|
|
|
|
trap _lp_runtime_before DEBUG
|
2015-04-01 07:08:31 -04:00
|
|
|
fi
|
2013-06-11 13:32:02 -04:00
|
|
|
fi
|
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
###############
|
|
|
|
# System load #
|
|
|
|
###############
|
|
|
|
|
|
|
|
# Compute a gradient of background/forground colors depending on the battery status
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_load_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2012-07-17 03:23:44 -04:00
|
|
|
# Colour progression is important ...
|
|
|
|
# bold gray -> bold green -> bold yellow -> bold red ->
|
|
|
|
# black on red -> bold white on red
|
|
|
|
#
|
|
|
|
# Then we have to choose the values at which the colours switch, with
|
|
|
|
# anything past yellow being pretty important.
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_LOAD )) || return
|
2012-08-16 12:35:07 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
local lp_cpu_load
|
|
|
|
# Get value (OS-specific) into lp_cpu_load
|
|
|
|
_lp_cpu_load
|
|
|
|
|
|
|
|
lp_cpu_load=${lp_cpu_load/./} # Remove '.'
|
|
|
|
lp_cpu_load=${lp_cpu_load#0} # Remove leading '0'
|
|
|
|
lp_cpu_load=${lp_cpu_load#0} # Remove leading '0', again (ex: 0.09)
|
|
|
|
local -i load=${lp_cpu_load:-0}/$_lp_CPUNUM
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2014-07-09 17:27:18 -04:00
|
|
|
if (( load > LP_LOAD_THRESHOLD )); then
|
2016-07-18 16:22:07 -04:00
|
|
|
local ret="$(_lp_color_map $load)${LP_MARK_LOAD}"
|
2013-03-13 07:30:41 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_PERCENTS_ALWAYS )); then
|
|
|
|
ret+="${load}${_LP_PERCENT}"
|
2012-08-13 09:20:20 -04:00
|
|
|
fi
|
2013-05-13 19:15:04 -04:00
|
|
|
echo -nE "${ret}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2013-04-24 03:48:18 -04:00
|
|
|
######################
|
|
|
|
# System temperature #
|
|
|
|
######################
|
2013-04-22 17:22:32 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Will set _LP_TEMP_FUNCTION so the temperature monitoring feature use an
|
|
|
|
# available command.
|
|
|
|
if (( LP_ENABLE_TEMP )); then
|
2013-04-24 03:48:18 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Backends for TEMP. Each backend must return the result in $temperature.
|
2013-12-04 18:00:38 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Implementation using lm-sensors
|
|
|
|
_lp_temp_sensors()
|
|
|
|
{
|
|
|
|
# Return the hottest system temperature we get through the sensors command
|
|
|
|
# Only the integer part is retained
|
|
|
|
local -i i
|
|
|
|
for i in $(sensors -u |
|
|
|
|
sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do
|
|
|
|
(( $i > ${temperature:-0} )) && temperature=i
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Implementation using 'acpi -t'
|
|
|
|
_lp_temp_acpi()
|
|
|
|
{
|
|
|
|
local -i i
|
|
|
|
# Only the integer part is retained
|
|
|
|
for i in $(LANG=C acpi -t |
|
|
|
|
sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do
|
|
|
|
(( $i > ${temperature:-0} )) && temperature=i
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Dynamic selection of backend
|
|
|
|
_lp_temp_detect()
|
|
|
|
{
|
|
|
|
local -i temperature
|
|
|
|
local cmd
|
|
|
|
|
|
|
|
# Global variable
|
|
|
|
unset _LP_TEMP_FUNCTION
|
|
|
|
|
|
|
|
for cmd
|
|
|
|
do
|
|
|
|
command -v $cmd >/dev/null || continue
|
|
|
|
|
|
|
|
_LP_TEMP_FUNCTION=_lp_temp_$cmd
|
|
|
|
# Check that we can retrieve temperature at least once
|
|
|
|
$_LP_TEMP_FUNCTION 2>/dev/null
|
|
|
|
# If $temperature is set, success!
|
|
|
|
[[ -n "$temperature" ]] && return 0
|
|
|
|
unset -f $_LP_TEMP_FUNCTION
|
|
|
|
unset _LP_TEMP_FUNCTION
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Try each _lp_temp method
|
|
|
|
# If no function worked, disable the feature
|
|
|
|
_lp_temp_detect acpi sensors || LP_ENABLE_TEMP=0
|
|
|
|
unset -f _lp_temp_detect
|
2013-04-24 03:48:18 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Will display the numeric value as we get through the _LP_TEMP_FUNCTION
|
|
|
|
# and colorize it through _lp_color_map.
|
|
|
|
_lp_temperature()
|
|
|
|
{
|
|
|
|
(( LP_ENABLE_TEMP )) || return
|
|
|
|
|
|
|
|
local -i temperature
|
2013-12-04 18:24:19 -05:00
|
|
|
temperature=0
|
|
|
|
$_LP_TEMP_FUNCTION
|
2016-07-18 16:22:07 -04:00
|
|
|
(( temperature >= LP_TEMP_THRESHOLD )) && \
|
|
|
|
echo -nE "${LP_MARK_TEMP}$(_lp_color_map $temperature 120)$temperature°${NO_COL}"
|
2013-04-21 10:16:06 -04:00
|
|
|
}
|
2012-07-19 05:21:18 -04:00
|
|
|
|
|
|
|
##########
|
|
|
|
# DESIGN #
|
|
|
|
##########
|
|
|
|
|
2013-12-27 18:29:33 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Sed expression using extended regexp to match terminal
|
|
|
|
# escape sequences with their wrappers
|
|
|
|
if $_LP_SHELL_bash; then
|
|
|
|
_LP_CLEAN_ESC='\\\[([^\]+|\\[^]])*\\\]'
|
|
|
|
else
|
|
|
|
_LP_CLEAN_ESC='%\{([^%]+|%[^}])*%\}'
|
|
|
|
fi
|
2013-12-27 18:29:33 -05:00
|
|
|
|
2013-01-10 11:18:45 -05:00
|
|
|
# Remove all colors and escape characters of the given string and return a pure text
|
|
|
|
_lp_as_text()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
# Remove all terminal sequences that we wrapped with $_LP_OPEN_ESC and
|
|
|
|
# $_LP_CLOSE_ESC.
|
|
|
|
echo -nE "$1" | sed -$_LP_SED_EXTENDED "s,$_LP_CLEAN_ESC,,g"
|
2013-01-10 11:18:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_lp_title()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_ENABLE_TITLE )) || return
|
2013-01-10 11:18:45 -05:00
|
|
|
|
|
|
|
# Get the current computed prompt as pure text
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${_LP_OPEN_ESC}${LP_TITLE_OPEN}"
|
|
|
|
_lp_as_text "$1"
|
|
|
|
echo -nE "${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
|
2013-01-10 11:18:45 -05:00
|
|
|
}
|
|
|
|
|
2012-08-10 08:40:50 -04:00
|
|
|
# Set the prompt mark to ± if git, to ☿ if mercurial, to ‡ if subversion
|
|
|
|
# to # if root and else $
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_smart_mark()
|
2012-07-17 03:22:40 -04:00
|
|
|
{
|
2012-08-13 17:15:24 -04:00
|
|
|
local mark
|
2013-06-12 20:26:40 -04:00
|
|
|
case "$LP_VCS_TYPE" in
|
|
|
|
git) mark="$LP_MARK_GIT" ;;
|
|
|
|
git-svn) mark="$LP_MARK_GIT$LP_MARK_SVN" ;;
|
2014-03-11 14:01:01 -04:00
|
|
|
git-vcsh) mark="$LP_MARK_VCSH$LP_MARK_GIT$LP_MARK_VCSH";;
|
2013-06-12 20:26:40 -04:00
|
|
|
hg) mark="$LP_MARK_HG" ;;
|
|
|
|
svn) mark="$LP_MARK_SVN" ;;
|
|
|
|
fossil) mark="$LP_MARK_FOSSIL" ;;
|
|
|
|
bzr) mark="$LP_MARK_BZR" ;;
|
|
|
|
disabled) mark="$LP_MARK_DISABLED" ;;
|
2014-06-27 19:49:56 -04:00
|
|
|
*) mark="$LP_MARK_DEFAULT" ;;
|
2013-06-12 20:26:40 -04:00
|
|
|
esac
|
2016-07-18 16:22:07 -04:00
|
|
|
echo -nE "${mark}${NO_COL}"
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
# insert a space on the right
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_sr()
|
2012-07-19 05:14:42 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
[[ -n "$1" ]] && echo -nE "$1 "
|
2012-07-19 05:14:42 -04:00
|
|
|
}
|
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
# insert a space on the left
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_sl()
|
2012-07-19 05:14:42 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
[[ -n "$1" ]] && echo -nE " $1"
|
2012-07-19 05:14:42 -04:00
|
|
|
}
|
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
# insert two space, before and after
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_sb()
|
2012-07-19 05:14:42 -04:00
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
[[ -n "$1" ]] && echo -nE " $1 "
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
|
|
|
|
2012-08-17 09:47:44 -04:00
|
|
|
###################
|
|
|
|
# CURRENT TIME #
|
|
|
|
###################
|
2013-04-21 18:07:45 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# LP_TIME is set colored, with a space on the right side
|
|
|
|
if (( LP_ENABLE_TIME )); then
|
|
|
|
if (( LP_TIME_ANALOG )); then
|
|
|
|
typeset -i _LP_CLOCK_PREV=-1
|
|
|
|
# The targeted unicode characters are the "CLOCK FACE" ones
|
|
|
|
# They are located in the codepages between:
|
|
|
|
# U+1F550 (ONE OCLOCK) and U+1F55B (TWELVE OCLOCK), for the plain hours
|
|
|
|
# U+1F55C (ONE-THIRTY) and U+1F567 (TWELVE-THIRTY), for the thirties
|
|
|
|
# Generated with:
|
|
|
|
# perl -C -E 'say join("", map {chr(0x1F550+$_)." ".chr(0x1F55C+$_)." "} 0..11)'
|
|
|
|
_LP_CLOCK=(🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧 )
|
|
|
|
|
|
|
|
_lp_time()
|
|
|
|
{
|
|
|
|
# %I: "00".."12" %M: "00".."59"
|
|
|
|
# Bash interprets a '0' prefix as octal
|
|
|
|
# so we have to clean that
|
|
|
|
local hhmm="$(date "+hh=%I mm=%M")"
|
|
|
|
# hh: 1..12 mm: 0..59
|
|
|
|
local -i hh mm clock
|
|
|
|
eval ${hhmm//=0/=} # Line split for zsh
|
|
|
|
# clock: 0 .. 25
|
|
|
|
# 1:00..1:14 -> 0
|
|
|
|
# 1:15..1:44 -> 1
|
|
|
|
# 1:45..2:15 -> 2
|
|
|
|
# ...
|
|
|
|
# 12:15..12:44 -> 23
|
|
|
|
# 12:45..12:59 -> 0
|
|
|
|
if (( ( clock=((hh*60+mm-45)/30)%24 ) != _LP_CLOCK_PREV )); then
|
|
|
|
# There is a space just after the clock char because the glyph
|
|
|
|
# width is twice usual glyphs
|
|
|
|
LP_TIME="${LP_COLOR_TIME}${_LP_CLOCK[clock+_LP_FIRST_INDEX]} ${NO_COL} "
|
|
|
|
_LP_CLOCK_PREV=clock
|
|
|
|
fi
|
|
|
|
}
|
2013-04-21 18:07:45 -04:00
|
|
|
else
|
2016-07-18 16:22:07 -04:00
|
|
|
# Never changes
|
|
|
|
LP_TIME="${LP_COLOR_TIME}${_LP_TIME_SYMBOL}${NO_COL} "
|
|
|
|
_lp_time() { : ; }
|
2013-04-21 18:07:45 -04:00
|
|
|
fi
|
2016-07-18 16:22:07 -04:00
|
|
|
else
|
|
|
|
LP_TIME=""
|
|
|
|
_lp_time() { : ; }
|
|
|
|
fi
|
2013-04-20 15:51:55 -04:00
|
|
|
|
2012-08-17 09:47:44 -04:00
|
|
|
|
2012-07-19 05:21:18 -04:00
|
|
|
########################
|
|
|
|
# Construct the prompt #
|
|
|
|
########################
|
|
|
|
|
2013-01-10 11:18:45 -05:00
|
|
|
|
2012-08-16 14:18:29 -04:00
|
|
|
_lp_set_prompt()
|
2012-07-17 03:22:40 -04:00
|
|
|
{
|
2013-05-22 17:56:50 -04:00
|
|
|
# Display the return value of the last command, if different from zero
|
|
|
|
# As this get the last returned code, it should be called first
|
|
|
|
local -i err=$?
|
|
|
|
if (( err != 0 )); then
|
|
|
|
LP_ERR=" $LP_COLOR_ERR$err$NO_COL"
|
|
|
|
else
|
2014-07-09 17:18:43 -04:00
|
|
|
LP_ERR='' # Hidden
|
2013-05-22 17:56:50 -04:00
|
|
|
fi
|
2012-07-19 05:27:22 -04:00
|
|
|
|
2013-05-13 18:34:48 -04:00
|
|
|
# Reset IFS to its default value to avoid strange behaviors
|
|
|
|
# (in case the user is playing with the value at the prompt)
|
2014-01-22 16:56:48 -05:00
|
|
|
local IFS="$_LP_IFS"
|
2016-07-18 16:22:07 -04:00
|
|
|
local GREP_OPTIONS=
|
2013-05-13 18:34:48 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# bash: execute the old prompt hook
|
|
|
|
eval "$LP_OLD_PROMPT_COMMAND"
|
2012-08-05 05:19:19 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# left of main prompt: space at right
|
2013-06-02 06:14:58 -04:00
|
|
|
LP_JOBS="$(_lp_sr "$(_lp_jobcount_color)")"
|
|
|
|
LP_TEMP="$(_lp_sr "$(_lp_temperature)")"
|
|
|
|
LP_LOAD="$(_lp_sr "$(_lp_load_color)")"
|
|
|
|
LP_BATT="$(_lp_sr "$(_lp_battery_color)")"
|
2016-07-18 16:22:07 -04:00
|
|
|
_lp_time
|
|
|
|
_lp_sudo_check
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# in main prompt: no space
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$LP_ENABLE_PROXY,${http_proxy-}" = 1,?* ]]; then
|
2013-06-12 18:25:39 -04:00
|
|
|
LP_PROXY="$LP_COLOR_PROXY$LP_MARK_PROXY$NO_COL"
|
|
|
|
else
|
|
|
|
LP_PROXY=
|
|
|
|
fi
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2014-06-27 19:57:24 -04:00
|
|
|
# Display the current Python virtual environment, if available
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$LP_ENABLE_VIRTUALENV,${VIRTUAL_ENV-}${CONDA_DEFAULT_ENV-}" = 1,?* ]]; then
|
|
|
|
if [[ -n "${VIRTUAL_ENV-}" ]]; then
|
|
|
|
LP_VENV=" [${LP_COLOR_VIRTUALENV}${VIRTUAL_ENV##*/}${NO_COL}]"
|
|
|
|
else
|
|
|
|
LP_VENV=" [${LP_COLOR_VIRTUALENV}${CONDA_DEFAULT_ENV##*/}${NO_COL}]"
|
|
|
|
fi
|
2014-01-06 16:10:42 -05:00
|
|
|
else
|
|
|
|
LP_VENV=
|
|
|
|
fi
|
2013-06-11 13:32:02 -04:00
|
|
|
|
2014-05-15 11:45:26 -04:00
|
|
|
# Display the current software collections enabled, if available
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "$LP_ENABLE_SCLS,${X_SCLS-}" = 1,?* ]]; then
|
2014-05-15 11:45:26 -04:00
|
|
|
LP_SCLS=" [${LP_COLOR_VIRTUALENV}${X_SCLS%"${X_SCLS##*[![:space:]]}"}${NO_COL}]"
|
|
|
|
else
|
|
|
|
LP_SCLS=
|
|
|
|
fi
|
|
|
|
|
2013-06-11 13:32:02 -04:00
|
|
|
LP_RUNTIME=$(_lp_sl "$(_lp_runtime)")
|
|
|
|
|
2014-01-06 16:10:42 -05:00
|
|
|
# if change of working directory
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ "${LP_OLD_PWD-}" != "LP:$PWD" ]]; then
|
2013-06-17 15:40:56 -04:00
|
|
|
# Update directory icon for MacOS X
|
|
|
|
$_LP_TERM_UPDATE_DIR
|
|
|
|
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS=""
|
|
|
|
LP_VCS_TYPE=""
|
2013-01-23 12:17:24 -05:00
|
|
|
# LP_HOST is a global set at load time
|
2014-01-06 15:38:15 -05:00
|
|
|
|
|
|
|
# LP_PERM: shows a ":"
|
|
|
|
# - colored in green if user has write permission on the current dir
|
|
|
|
# - colored in red if not
|
2016-07-18 16:22:07 -04:00
|
|
|
if (( LP_ENABLE_PERM )); then
|
2014-01-06 15:38:15 -05:00
|
|
|
if [[ -w "${PWD}" ]]; then
|
|
|
|
LP_PERM="${LP_COLOR_WRITE}:${NO_COL}"
|
|
|
|
else
|
|
|
|
LP_PERM="${LP_COLOR_NOWRITE}:${NO_COL}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-12-16 18:12:14 -05:00
|
|
|
_lp_shorten_path # set LP_PWD
|
2013-01-23 12:17:24 -05:00
|
|
|
|
2013-05-16 16:31:34 -04:00
|
|
|
if _lp_are_vcs_enabled; then
|
2013-01-23 12:17:24 -05:00
|
|
|
LP_VCS="$(_lp_git_branch_color)"
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS_TYPE="git"
|
2013-03-20 08:56:44 -04:00
|
|
|
if [[ -n "$LP_VCS" ]]; then
|
2014-03-11 14:01:01 -04:00
|
|
|
# If this is a vcsh repository
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -n "${VCSH_DIRECTORY-}" ]]; then
|
2014-03-11 14:01:01 -04:00
|
|
|
LP_VCS_TYPE="git-vcsh"
|
|
|
|
fi
|
2013-03-20 08:56:44 -04:00
|
|
|
# If this is a git-svn repository
|
2013-07-26 04:30:50 -04:00
|
|
|
if [[ -d "$(\git rev-parse --git-dir 2>/dev/null)/svn" ]]; then
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS_TYPE="git-svn"
|
2013-05-16 16:31:34 -04:00
|
|
|
fi # git-svn
|
|
|
|
else
|
2013-01-23 12:17:24 -05:00
|
|
|
LP_VCS="$(_lp_hg_branch_color)"
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS_TYPE="hg"
|
2013-01-23 09:44:42 -05:00
|
|
|
if [[ -z "$LP_VCS" ]]; then
|
2013-01-23 12:17:24 -05:00
|
|
|
LP_VCS="$(_lp_svn_branch_color)"
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS_TYPE="svn"
|
2013-01-23 09:44:42 -05:00
|
|
|
if [[ -z "$LP_VCS" ]]; then
|
2013-01-23 12:17:24 -05:00
|
|
|
LP_VCS="$(_lp_fossil_branch_color)"
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS_TYPE="fossil"
|
2013-01-23 12:17:24 -05:00
|
|
|
if [[ -z "$LP_VCS" ]]; then
|
|
|
|
LP_VCS="$(_lp_bzr_branch_color)"
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS_TYPE="bzr"
|
|
|
|
if [[ -z "$LP_VCS" ]]; then
|
|
|
|
LP_VCS=""
|
|
|
|
LP_VCS_TYPE=""
|
|
|
|
fi # nothing
|
2013-03-20 08:56:44 -04:00
|
|
|
fi # bzr
|
|
|
|
fi # fossil
|
|
|
|
fi # svn
|
|
|
|
fi # hg
|
2013-04-22 13:07:34 -04:00
|
|
|
|
|
|
|
else # if this vcs rep is disabled
|
|
|
|
LP_VCS="" # not necessary, but more readable
|
|
|
|
LP_VCS_TYPE="disabled"
|
|
|
|
fi
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -z "$LP_VCS_TYPE" ]]; then
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_VCS=""
|
2013-01-23 09:44:42 -05:00
|
|
|
else
|
2013-06-02 06:14:58 -04:00
|
|
|
LP_VCS="$(_lp_sl "${LP_VCS}")"
|
2013-01-23 09:44:42 -05:00
|
|
|
fi
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2013-01-23 12:17:24 -05:00
|
|
|
# end of the prompt line: double spaces
|
2014-03-08 23:04:35 -05:00
|
|
|
LP_MARK="$(_lp_sr "$(_lp_smart_mark $LP_VCS_TYPE)")"
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2013-08-13 12:23:38 -04:00
|
|
|
LP_OLD_PWD="LP:$PWD"
|
2013-01-23 12:17:24 -05:00
|
|
|
|
2013-04-22 13:07:34 -04:00
|
|
|
# if do not change of working directory but...
|
|
|
|
elif [[ -n "$LP_VCS_TYPE" ]]; then # we are still in a VCS dir
|
|
|
|
case "$LP_VCS_TYPE" in
|
2013-05-22 18:23:56 -04:00
|
|
|
# git, git-svn
|
2013-06-02 06:14:58 -04:00
|
|
|
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)")";;
|
2013-04-22 13:07:34 -04:00
|
|
|
disabled)LP_VCS="";;
|
2013-01-23 12:17:24 -05:00
|
|
|
esac
|
2012-08-16 06:13:40 -04:00
|
|
|
fi
|
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -f "${LP_PS1_FILE-}" ]]; then
|
2013-03-12 17:14:09 -04:00
|
|
|
source "$LP_PS1_FILE"
|
|
|
|
fi
|
2013-03-12 16:02:28 -04:00
|
|
|
|
2015-01-05 16:48:47 -05:00
|
|
|
if $_LP_SHELL_zsh; then
|
2014-11-16 10:54:22 -05:00
|
|
|
# If ZSH, use PS1 and RPS1
|
|
|
|
if [[ -z "$LP_PS1" ]] ; then
|
|
|
|
# add title, host, and permissions colon
|
|
|
|
PS1="${LP_PS1_PREFIX}${LP_JOBS}${LP_BRACKET_OPEN}${LP_USER}${LP_HOST}${LP_PERM}"
|
|
|
|
# Add current directory, software collections, virtual enviornment, and proxy
|
|
|
|
PS1="${PS1}${LP_PWD}${LP_BRACKET_CLOSE}${LP_SCLS}${LP_VENV}${LP_PROXY}"
|
|
|
|
# Add VCS infos
|
|
|
|
# If root, the info has not been collected unless LP_ENABLE_VCS_ROOT
|
|
|
|
# is set.
|
2016-07-18 16:22:07 -04:00
|
|
|
PS1+="${LP_VCS}"
|
2013-06-11 16:37:14 -04:00
|
|
|
|
2014-11-16 10:54:22 -05:00
|
|
|
# add return code and prompt mark
|
2016-07-18 16:22:07 -04:00
|
|
|
PS1+="${LP_RUNTIME}${LP_ERR}${LP_MARK_PREFIX}${LP_COLOR_MARK}${LP_MARK}${LP_PS1_POSTFIX}"
|
2012-08-10 09:46:44 -04:00
|
|
|
|
2014-11-16 10:54:22 -05:00
|
|
|
# "invisible" parts
|
|
|
|
# Get the current prompt on the fly and make it a title
|
|
|
|
LP_TITLE="$(_lp_title "$PS1")"
|
2013-01-10 11:18:45 -05:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# Insert it in the prompt
|
|
|
|
PS1="${LP_TITLE}${PS1}"
|
|
|
|
|
2014-11-16 10:54:22 -05:00
|
|
|
# Insert it in the prompt
|
|
|
|
PS1="${LP_TITLE}${PS1}"
|
2014-11-16 11:42:22 -05:00
|
|
|
[[ $LP_ENABLE_OHMYGIT = 1 ]] && PS1="$(build_prompt)$PS1"
|
2014-11-16 10:54:22 -05:00
|
|
|
else
|
|
|
|
PS1=$LP_PS1
|
2014-11-16 11:42:22 -05:00
|
|
|
[[ $LP_ENABLE_OHMYGIT = 1 ]] && PS1="$(build_prompt)$PS1"
|
2014-11-16 10:54:22 -05:00
|
|
|
fi
|
|
|
|
if [[ -z "$LP_RPS1" ]] ; then
|
|
|
|
RPS1="${LP_TIME}${LP_LOAD}${LP_TEMP}${LP_BATT}"
|
|
|
|
else
|
|
|
|
RPS1=$LP_RPS1
|
|
|
|
fi
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2014-11-16 10:54:22 -05:00
|
|
|
# If not ZSH, use only PS1
|
|
|
|
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
|
|
|
|
PS1="${PS1}${LP_BRACKET_OPEN}${LP_USER}${LP_HOST}${LP_PERM}"
|
|
|
|
|
|
|
|
PS1="${PS1}${LP_PWD}${LP_BRACKET_CLOSE}${LP_SCLS}${LP_VENV}${LP_PROXY}"
|
|
|
|
|
|
|
|
# Add VCS infos
|
|
|
|
# If root, the info has not been collected unless LP_ENABLE_VCS_ROOT
|
|
|
|
# is set.
|
|
|
|
PS1="${PS1}${LP_VCS}"
|
|
|
|
|
|
|
|
# add return code and prompt mark
|
|
|
|
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
|
|
|
|
LP_TITLE="$(_lp_title "$PS1")"
|
|
|
|
|
|
|
|
# Insert it in the prompt
|
|
|
|
PS1="${LP_TITLE}${PS1}"
|
2014-11-16 11:42:22 -05:00
|
|
|
[[ $LP_ENABLE_OHMYGIT = 1 ]] && PS1="$(build_prompt)$PS1"
|
2014-11-16 10:54:22 -05:00
|
|
|
fi
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
2013-01-10 11:18:45 -05:00
|
|
|
|
2013-03-11 18:05:10 -04:00
|
|
|
prompt_tag()
|
2013-02-26 07:37:31 -05:00
|
|
|
{
|
2013-06-02 06:14:58 -04:00
|
|
|
export LP_PS1_PREFIX="$(_lp_sr "$1")"
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2014-12-09 01:27:11 -05:00
|
|
|
# Activate Liquid Prompt
|
2012-08-04 13:05:34 -04:00
|
|
|
prompt_on()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
# Reset so all PWD dependent variables are computed after loading
|
|
|
|
LP_OLD_PWD=""
|
|
|
|
|
2014-12-09 01:27:11 -05:00
|
|
|
# if Liquid Prompt has not been already set
|
2016-07-18 16:22:07 -04:00
|
|
|
if [[ -z "${LP_OLD_PS1-}" ]]; then
|
2012-08-07 15:29:44 -04:00
|
|
|
LP_OLD_PS1="$PS1"
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2012-08-11 18:46:05 -04:00
|
|
|
LP_OLD_PROMPT_COMMAND="$PROMPT_COMMAND"
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_OLD_SHOPT="$(shopt -p promptvars)"
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2016-07-18 16:22:07 -04:00
|
|
|
LP_OLD_PROMPT_COMMAND=""
|
|
|
|
_LP_ZSH_PROMPT_THEME=""
|
|
|
|
if [[ -n "$prompt_theme" && "$prompt_theme" != off ]]; then
|
|
|
|
_LP_ZSH_PROMPT_THEME="$prompt_theme"
|
|
|
|
# Disable the prompt to disable its precmd hook
|
|
|
|
prompt off
|
|
|
|
fi
|
|
|
|
_LP_OLD_SETOPT=()
|
|
|
|
# Dump option names: echo ${(ko)options}
|
|
|
|
for o in promptpercent promptbang promptsubst
|
|
|
|
do
|
|
|
|
if [[ "${options[$o]}" = on ]]; then
|
|
|
|
_LP_OLD_SETOPT+=$o
|
|
|
|
else
|
|
|
|
_LP_OLD_SETOPT+=no$o
|
|
|
|
fi
|
|
|
|
done
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
|
|
|
fi
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2016-07-18 16:22:07 -04:00
|
|
|
# Disable parameter/command expansion from PS1
|
|
|
|
shopt -u promptvars
|
2012-08-16 14:18:29 -04:00
|
|
|
PROMPT_COMMAND=_lp_set_prompt
|
2016-07-18 16:22:07 -04:00
|
|
|
(( LP_DEBUG_TIME )) && PROMPT_COMMAND="time $PROMPT_COMMAND" || true
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2016-07-18 16:22:07 -04:00
|
|
|
[[ -n "$_LP_ZSH_HOOK" ]] && add-zsh-hook -d precmd $_LP_ZSH_HOOK
|
|
|
|
# Set options that affect PS1 evaluation
|
|
|
|
# Disable parameter/command expansion; enable percent expansion
|
|
|
|
setopt promptpercent nopromptbang nopromptsubst
|
|
|
|
# 'time' doesn't seem to work on shell functions: no time output
|
|
|
|
#if (( LP_DEBUG_TIME )); then
|
|
|
|
# _lp_main_precmd() {
|
2014-12-09 01:27:11 -05:00
|
|
|
# local TIMEFMT='Liquid Prompt build time: %*E'
|
2013-06-12 09:11:13 -04:00
|
|
|
# time _lp_set_prompt
|
|
|
|
# }
|
2016-07-18 16:22:07 -04:00
|
|
|
# _LP_ZSH_HOOK=_lp_main_precmd
|
2013-06-12 09:11:13 -04:00
|
|
|
#else
|
2016-07-18 16:22:07 -04:00
|
|
|
_LP_ZSH_HOOK=_lp_set_prompt
|
2013-06-12 09:11:13 -04:00
|
|
|
#fi
|
2016-07-18 16:22:07 -04:00
|
|
|
add-zsh-hook precmd $_LP_ZSH_HOOK
|
2012-08-07 15:29:44 -04:00
|
|
|
fi
|
2012-08-04 13:05:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Come back to the old prompt
|
|
|
|
prompt_off()
|
|
|
|
{
|
2012-08-04 13:19:09 -04:00
|
|
|
PS1=$LP_OLD_PS1
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2016-07-18 16:22:07 -04:00
|
|
|
eval "$_LP_OLD_SHOPT"
|
2013-12-17 15:16:43 -05:00
|
|
|
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2016-07-18 16:22:07 -04:00
|
|
|
add-zsh-hook -d precmd $_LP_ZSH_HOOK
|
|
|
|
setopt ${_LP_OLD_SETOPT}
|
|
|
|
(( ${#_LP_ZSH_PROMPT_THEME} )) && prompt $_LP_ZSH_PROMPT_THEME
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
2012-08-04 13:05:34 -04:00
|
|
|
}
|
|
|
|
|
2012-08-11 04:20:37 -04:00
|
|
|
# Use an empty prompt: just the \$ mark
|
|
|
|
prompt_OFF()
|
|
|
|
{
|
2016-07-18 16:22:07 -04:00
|
|
|
PS1="$_LP_MARK_SYMBOL "
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2014-06-30 13:42:51 -04:00
|
|
|
shopt -u promptvars
|
2013-12-17 15:16:43 -05:00
|
|
|
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2016-07-18 16:22:07 -04:00
|
|
|
add-zsh-hook -d precmd $_LP_ZSH_HOOK
|
|
|
|
setopt promptpercent nopromptbang nopromptsubst
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
2012-08-11 04:20:37 -04:00
|
|
|
}
|
|
|
|
|
2014-12-09 01:27:11 -05:00
|
|
|
# By default, sourcing liquidprompt will activate Liquid Prompt
|
2012-08-04 13:05:34 -04:00
|
|
|
prompt_on
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2016-07-18 16:22:07 -04:00
|
|
|
# vim: set et sts=4 sw=4 tw=120 ft=sh:
|