2012-07-07 03:32:29 -04:00
|
|
|
|
2012-08-04 06:05:03 -04:00
|
|
|
################################################################################
|
|
|
|
# LIQUID PROMPT
|
2012-08-11 18:46:05 -04: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-04-09 18:55:24 -04:00
|
|
|
# Alex Prengère <alexprengere@gmail.com> # untracked git files
|
2013-03-13 07:14:48 -04:00
|
|
|
# Aurelien Requiem <aurelien@requiem.fr> # Major clean refactoring, variable path length, error codes, several bugfixes.
|
2013-05-03 15:06:08 -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
|
|
|
|
# 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-01-10 05:58:28 -05:00
|
|
|
# François Schmidts <francois.schmidts@gmail.com> # small code fix, _lp_get_dirtrim
|
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.
|
|
|
|
# Joris Vaillant <joris.vaillant@gmail.com> # small git fix
|
|
|
|
# Luc Didry <luc@fiat-tux.fr> # Zsh port, several fix
|
|
|
|
# Ludovic Rousseau <ludovic.rousseau@gmail.com> # Lot of bugfixes.
|
|
|
|
# Nicolas Lacourte <nicolas@dotinfra.fr> # screen title
|
|
|
|
# nojhan <nojhan@gmail.com> # Main author.
|
2013-05-03 17:44:07 -04:00
|
|
|
# Olivier Mengué <dolmen@cpan.org> # Major optimizations and refactorings everywhere.
|
2013-03-13 07:14:48 -04:00
|
|
|
# Poil <poil@quake.fr> # speed improvements
|
|
|
|
# Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use.
|
|
|
|
# Yann 'Ze' Richard <ze@nbox.org> # Do not fail on missing commands.
|
2012-08-04 06:05:03 -04:00
|
|
|
|
|
|
|
# See the README.md file for a summary of features.
|
|
|
|
|
2012-08-14 06:08:43 -04:00
|
|
|
# Check for recent enough version of bash.
|
|
|
|
if test -n "$BASH_VERSION" -a -n "$PS1" -a -n "$TERM" ; then
|
2012-08-11 18:46:05 -04:00
|
|
|
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
|
|
|
|
if [[ $bmajor -lt 3 ]] || [[ $bmajor -eq 3 && $bminor -lt 2 ]]; then
|
|
|
|
unset bash bmajor bminor
|
|
|
|
return
|
|
|
|
fi
|
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="\]"
|
2012-08-13 17:15:24 -04:00
|
|
|
_LP_USER_SYMBOL="\u"
|
|
|
|
_LP_HOST_SYMBOL="\h"
|
2013-05-04 16:58:12 -04:00
|
|
|
_LP_TIME_SYMBOL="\t"
|
2013-06-02 05:02:34 -04:00
|
|
|
_LP_FIRST_INDEX=0
|
2012-08-14 06:08:43 -04:00
|
|
|
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="%}"
|
2012-08-13 17:15:24 -04:00
|
|
|
_LP_USER_SYMBOL="%n"
|
|
|
|
_LP_HOST_SYMBOL="%m"
|
2013-01-25 07:17:05 -05:00
|
|
|
_LP_TIME_SYMBOL="%*"
|
2013-06-02 05:02:34 -04:00
|
|
|
_LP_FIRST_INDEX=1
|
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
|
|
|
|
|
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 ;;
|
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
|
2012-08-15 18:22:49 -04:00
|
|
|
Linux) _lp_CPUNUM=$( nproc 2>/dev/null || grep -c '^[Pp]rocessor' /proc/cpuinfo ) ;;
|
2012-08-21 17:35:14 -04:00
|
|
|
FreeBSD|Darwin) _lp_CPUNUM=$( sysctl -n hw.ncpu ) ;;
|
2012-08-14 17:24:55 -04:00
|
|
|
SunOS) _lp_CPUNUM=$( kstat -m cpu_info | grep -c "module: cpu_info" ) ;;
|
|
|
|
esac
|
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 () {
|
|
|
|
local load eol
|
|
|
|
read load eol < /proc/loadavg
|
|
|
|
echo "$load"
|
|
|
|
}
|
|
|
|
;;
|
2012-08-21 17:49:55 -04:00
|
|
|
FreeBSD)
|
2012-08-14 18:11:34 -04:00
|
|
|
_lp_cpu_load () {
|
|
|
|
local bol load eol
|
|
|
|
read bol load eol < $<( LANG=C sysctl -n vm.loadavg )
|
|
|
|
echo "$load"
|
|
|
|
}
|
|
|
|
;;
|
2012-08-21 17:49:55 -04:00
|
|
|
Darwin)
|
|
|
|
_lp_cpu_load () {
|
|
|
|
local load
|
|
|
|
load=$(LANG=C sysctl -n vm.loadavg | awk '{print $2}')
|
|
|
|
echo "$load"
|
|
|
|
}
|
2013-01-25 06:06:48 -05:00
|
|
|
LP_DWIN_KERNEL_REL_VER=$(uname -r | cut -d . -f 1)
|
2012-08-21 17:49:55 -04:00
|
|
|
;;
|
2012-08-14 18:11:34 -04:00
|
|
|
SunOS)
|
|
|
|
_lp_cpu_load () {
|
|
|
|
LANG=C uptime | awk '{print substr($10,0,length($10))}'
|
|
|
|
}
|
|
|
|
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:
|
2012-08-21 01:51:40 -04:00
|
|
|
# 1. Setup variables that can be used by the user: the "API" of liquidprompt
|
|
|
|
# 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
|
2012-08-21 01:21:25 -04:00
|
|
|
if tput setaf >/dev/null 2>&1 ; then
|
2012-08-21 01:52:25 -04:00
|
|
|
ti_setaf () { tput setaf "$1" ; }
|
2012-08-21 01:21:25 -04:00
|
|
|
elif tput AF >/dev/null 2>&1 ; then
|
|
|
|
# *BSD
|
2012-08-21 01:52:25 -04:00
|
|
|
ti_setaf () { tput AF "$1" ; }
|
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
|
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}"
|
|
|
|
local WARN_RED="${_LP_OPEN_ESC}$(ti_setaf 0 ; tput setab 1)${_LP_CLOSE_ESC}"
|
|
|
|
local CRIT_RED="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 7 ; tput setab 1)${_LP_CLOSE_ESC}"
|
|
|
|
local DANGER_RED="${_LP_OPEN_ESC}${ti_bold}$(ti_setaf 3 ; tput 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
|
|
|
|
2012-08-21 01:52:25 -04:00
|
|
|
unset ti_sgr0 ti_bold ti_setaf
|
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}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
|
|
|
|
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
|
|
|
|
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:-""}
|
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:-""}
|
2013-01-10 11:18:45 -05:00
|
|
|
LP_TITLE_OPEN=${LP_TITLE_OPEN:-"\e]0;"}
|
|
|
|
LP_TITLE_CLOSE=${LP_TITLE_CLOSE:-"\a"}
|
2013-03-07 19:59:06 -05:00
|
|
|
LP_SCREEN_TITLE_OPEN=${LP_SCREEN_TITLE_OPEN:-"\033k"}
|
|
|
|
LP_SCREEN_TITLE_CLOSE=${LP_SCREEN_TITLE_CLOSE:-"\033\134"}
|
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}
|
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}
|
2012-11-03 17:09:50 -04:00
|
|
|
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-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}
|
2013-01-23 07:36:29 -05:00
|
|
|
LP_DISABLED_VCS_PATH=${LP_DISABLED_VCS_PATH:-""}
|
2013-01-04 06:13:00 -05:00
|
|
|
|
2013-04-17 08:12:17 -04:00
|
|
|
LP_MARK_DEFAULT=${LP_MARK_DEFAULT:-""}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"}
|
|
|
|
LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"}
|
|
|
|
LP_MARK_LOAD=${LP_MARK_LOAD:-"⌂"}
|
2013-04-22 17:22:32 -04:00
|
|
|
LP_MARK_TEMP=${LP_MARK_TEMP:-"θ"}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_MARK_PROXY=${LP_MARK_PROXY:-"↥"}
|
|
|
|
LP_MARK_HG=${LP_MARK_HG:-"☿"}
|
|
|
|
LP_MARK_SVN=${LP_MARK_SVN:-"‡"}
|
|
|
|
LP_MARK_GIT=${LP_MARK_GIT:-"±"}
|
2012-12-28 20:42:29 -05:00
|
|
|
LP_MARK_FOSSIL=${LP_MARK_FOSSIL:-"⌘"}
|
2013-01-17 11:20:15 -05:00
|
|
|
LP_MARK_BZR=${LP_MARK_BZR:-"⚯"}
|
2013-04-22 13:07:34 -04:00
|
|
|
LP_MARK_DISABLED=${LP_MARK_DISABLED:-"⌀"}
|
2012-08-21 01:07:34 -04:00
|
|
|
LP_MARK_UNTRACKED=${LP_MARK_UNTRACKED:-"*"}
|
2013-01-17 17:02:17 -05:00
|
|
|
LP_MARK_STASH=${LP_MARK_STASH:-"+"}
|
2013-02-26 08:18:58 -05:00
|
|
|
LP_MARK_BRACKET_OPEN=${LP_MARK_BRACKET_OPEN:-"["}
|
|
|
|
LP_MARK_BRACKET_CLOSE=${LP_MARK_BRACKET_CLOSE:-"]"}
|
2013-03-21 16:22:20 -04:00
|
|
|
LP_MARK_SHORTEN_PATH=${LP_MARK_SHORTEN_PATH:-" … "}
|
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}
|
|
|
|
LP_COLOR_USER_LOGGED=${LP_COLOR_USER_LOGGED:-""}
|
|
|
|
LP_COLOR_USER_ALT=${LP_COLOR_USER_ALT:-$BOLD}
|
|
|
|
LP_COLOR_USER_ROOT=${_ROOT:-$BOLD_YELLOW}
|
|
|
|
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}
|
2012-09-25 15:09:51 -04:00
|
|
|
LP_COLOR_X11_ON=${LP_COLOR_X11:-$GREEN}
|
|
|
|
LP_COLOR_X11_OFF=${LP_COLOR_X11:-$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}
|
|
|
|
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}
|
2012-08-21 01:07:34 -04:00
|
|
|
|
|
|
|
LP_COLORMAP_0=${LP_COLORMAP_0:-""}
|
|
|
|
LP_COLORMAP_1=${LP_COLORMAP_1:-$GREEN}
|
|
|
|
LP_COLORMAP_2=${LP_COLORMAP_2:-$BOLD_GREEN}
|
|
|
|
LP_COLORMAP_3=${LP_COLORMAP_3:-$YELLOW}
|
|
|
|
LP_COLORMAP_4=${LP_COLORMAP_4:-$BOLD_YELLOW}
|
|
|
|
LP_COLORMAP_5=${LP_COLORMAP_5:-$RED}
|
|
|
|
LP_COLORMAP_6=${LP_COLORMAP_6:-$BOLD_RED}
|
|
|
|
LP_COLORMAP_7=${LP_COLORMAP_7:-$WARN_RED}
|
|
|
|
LP_COLORMAP_8=${LP_COLORMAP_8:-$CRIT_RED}
|
|
|
|
LP_COLORMAP_9=${LP_COLORMAP_9:-$DANGER_RED}
|
2012-08-14 09:06:58 -04:00
|
|
|
|
|
|
|
|
2012-08-21 01:03:52 -04:00
|
|
|
# Default config file may be the XDG standard ~/.config/liquidpromptrc,
|
|
|
|
# but heirloom dotfile has priority.
|
|
|
|
|
2012-08-14 05:10:12 -04:00
|
|
|
local configfile
|
|
|
|
if [[ -f "/etc/liquidpromptrc" ]]
|
|
|
|
then
|
|
|
|
source "/etc/liquidpromptrc"
|
|
|
|
fi
|
|
|
|
if [[ -f "$HOME/.liquidpromptrc" ]]
|
|
|
|
then
|
|
|
|
configfile="$HOME/.liquidpromptrc"
|
|
|
|
elif [[ -z "$XDG_HOME_DIR" ]]
|
|
|
|
then
|
|
|
|
configfile="$HOME/.config/liquidpromptrc"
|
|
|
|
else
|
|
|
|
configfile="$XDG_HOME_DIR/liquidpromptrc"
|
|
|
|
fi
|
|
|
|
if [[ -f "$configfile" ]]
|
|
|
|
then
|
|
|
|
source "$configfile"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
# do source config files
|
|
|
|
_lp_source_config
|
2012-08-21 02:21:41 -04:00
|
|
|
unset _lp_source_config
|
2012-08-14 05:10:12 -04:00
|
|
|
|
2012-08-16 10:39:20 -04:00
|
|
|
# Disable features if the tool is not installed
|
2012-08-16 11:10:58 -04:00
|
|
|
[[ "$LP_ENABLE_GIT" = 1 ]] && { command -v git >/dev/null || LP_ENABLE_GIT=0 ; }
|
|
|
|
[[ "$LP_ENABLE_SVN" = 1 ]] && { command -v svn >/dev/null || LP_ENABLE_SVN=0 ; }
|
2012-12-28 20:42:29 -05:00
|
|
|
[[ "$LP_ENABLE_FOSSIL" = 1 ]] && { command -v fossil >/dev/null || LP_ENABLE_FOSSIL=0 ; }
|
2012-08-16 11:10:58 -04:00
|
|
|
[[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; }
|
2013-01-17 11:20:15 -05:00
|
|
|
[[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; }
|
2012-08-16 11:10:58 -04:00
|
|
|
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=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}"
|
|
|
|
else
|
|
|
|
LP_BRACKET_OPEN="${LP_MARK_BRACKET_OPEN}"
|
|
|
|
LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}"
|
2013-05-04 09:15:26 -04:00
|
|
|
fi
|
|
|
|
|
2013-03-13 10:58:56 -04:00
|
|
|
# Escape the given strings
|
2013-03-25 15:57:46 -04:00
|
|
|
# Must be used for all strings that may comes from remote sources,
|
2013-03-13 10:58:56 -04:00
|
|
|
# like VCS branch names
|
|
|
|
_lp_escape()
|
|
|
|
{
|
|
|
|
printf "%q" "$*"
|
|
|
|
}
|
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? #
|
|
|
|
###############
|
|
|
|
|
2012-08-14 06:01:14 -04:00
|
|
|
# Yellow for root, bold if the user is not the login one, else no color.
|
2013-01-25 06:20:19 -05:00
|
|
|
if [[ "$EUID" -ne "0" ]] ; then # if user is not root
|
|
|
|
# if user is not login user
|
2013-04-21 13:00:17 -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}"
|
|
|
|
else
|
|
|
|
if [[ "${LP_USER_ALWAYS}" -ne "0" ]] ; then
|
|
|
|
LP_USER="${LP_COLOR_USER_LOGGED}${_LP_USER_SYMBOL}${NO_COL}"
|
2012-07-19 09:08:18 -04:00
|
|
|
else
|
2013-01-25 06:20:19 -05:00
|
|
|
LP_USER=""
|
2012-07-19 09:08:18 -04:00
|
|
|
fi
|
|
|
|
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-01-25 06:20:19 -05:00
|
|
|
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
|
|
|
{
|
2013-03-14 13:15:55 -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
|
2012-08-14 09:11:48 -04:00
|
|
|
# TODO check on *BSD
|
2013-06-02 06:14:58 -04:00
|
|
|
local sess_src="$(who am i | sed -n 's/.*(\(.*\))/\1/p')"
|
|
|
|
local sess_parent="$(ps -o comm= -p $PPID 2> /dev/null)"
|
2012-09-05 13:44:53 -04:00
|
|
|
if [[ -z "$sess_src" || "$sess_src" = ":"* ]] ; then
|
2012-08-14 09:11:48 -04:00
|
|
|
echo lcl # Local
|
2013-03-14 13:15:55 -04:00
|
|
|
elif [[ "$sess_parent" = "su" || "$sess_parent" = "sudo" ]] ; then
|
|
|
|
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
|
|
|
|
# else diplay 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=""
|
2013-01-12 09:42:22 -05:00
|
|
|
_chroot()
|
|
|
|
{
|
|
|
|
if [[ -r /etc/debian_chroot ]] ; then
|
|
|
|
local debchroot
|
2013-06-02 06:14:58 -04:00
|
|
|
debchroot="$(cat /etc/debian_chroot)"
|
2013-01-12 09:42:22 -05:00
|
|
|
echo "(${debchroot})"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
LP_HOST="$(_chroot)"
|
|
|
|
unset _chroot
|
2012-09-09 16:43:10 -04:00
|
|
|
|
2012-09-23 17:07:51 -04:00
|
|
|
# If we are connected with a X11 support
|
|
|
|
if [[ -n "$DISPLAY" ]] ; then
|
2012-09-25 15:09:51 -04:00
|
|
|
LP_HOST="${LP_COLOR_X11_ON}${LP_HOST}@${NO_COL}"
|
2012-09-23 17:07:51 -04:00
|
|
|
else
|
2012-09-25 15:09:51 -04:00
|
|
|
LP_HOST="${LP_COLOR_X11_OFF}${LP_HOST}@${NO_COL}"
|
2012-09-23 17:07:51 -04:00
|
|
|
fi
|
|
|
|
|
2012-08-14 05:43:58 -04:00
|
|
|
case "$(_lp_connection)" in
|
|
|
|
lcl)
|
2013-02-20 04:20:42 -05:00
|
|
|
if [[ "${LP_HOSTNAME_ALWAYS}" -eq "0" ]] ; then
|
2012-09-09 16:43:10 -04:00
|
|
|
# FIXME do we want to display the chroot if local?
|
2013-01-25 05:48:03 -05:00
|
|
|
LP_HOST="" # no hostname if local
|
2012-07-17 03:50:30 -04:00
|
|
|
else
|
2012-09-09 16:43:10 -04:00
|
|
|
LP_HOST="${LP_HOST}${LP_COLOR_HOST}${_LP_HOST_SYMBOL}${NO_COL}"
|
2012-07-17 03:50:30 -04:00
|
|
|
fi
|
2012-08-14 09:11:48 -04:00
|
|
|
;;
|
2012-08-14 05:43:58 -04:00
|
|
|
ssh)
|
2013-03-11 19:02:04 -04:00
|
|
|
# If we want a different color for each host
|
2013-03-12 15:33:25 -04:00
|
|
|
if [[ "$LP_ENABLE_SSH_COLORS" -eq "1" ]]; then
|
2013-03-11 19:02:04 -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?)
|
|
|
|
hash=$(( 1 + $(hostname | cksum | cut -d " " -f 1) % 6 ))
|
|
|
|
color=${_LP_OPEN_ESC}$(ti_setaf $hash)${_LP_CLOSE_ESC}
|
|
|
|
LP_HOST="${LP_HOST}${color}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
unset hash
|
|
|
|
unset color
|
|
|
|
else
|
|
|
|
# the same color for all hosts
|
|
|
|
LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
fi
|
2012-08-14 09:11:48 -04:00
|
|
|
;;
|
2013-03-14 13:15:55 -04:00
|
|
|
su)
|
|
|
|
LP_HOST="${LP_HOST}${LP_COLOR_SU}${_LP_HOST_SYMBOL}${NO_COL}"
|
2012-08-14 09:11:48 -04:00
|
|
|
;;
|
2012-08-14 05:43:58 -04:00
|
|
|
tel)
|
2012-09-09 16:43:10 -04:00
|
|
|
LP_HOST="${LP_HOST}${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}"
|
2012-08-14 05:43:58 -04:00
|
|
|
;;
|
|
|
|
*)
|
2012-09-09 16:43:10 -04:00
|
|
|
LP_HOST="${LP_HOST}${_LP_HOST_SYMBOL}" # defaults to no color
|
2012-08-14 05:43:58 -04:00
|
|
|
;;
|
|
|
|
esac
|
2012-07-17 03:50:30 -04:00
|
|
|
|
2012-08-14 05:43:58 -04:00
|
|
|
# Useless now, so undefine
|
2012-09-05 13:44:53 -04:00
|
|
|
# unset _lp_connection
|
2012-07-17 03:50:30 -04:00
|
|
|
|
|
|
|
|
2012-08-09 06:11:51 -04:00
|
|
|
# put an arrow if an http proxy is set
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_proxy()
|
2012-08-09 06:11:51 -04:00
|
|
|
{
|
2013-05-03 17:42:26 -04:00
|
|
|
[[ "$LP_ENABLE_PROXY,$http_proxy" = 1,?* ]] && echo -ne "$LP_COLOR_PROXY$LP_MARK_PROXY$NO_COL"
|
2012-08-09 06:11:51 -04:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:46:05 -04:00
|
|
|
# BASH/ZSH function that shortens
|
2012-07-29 16:19:06 -04:00
|
|
|
# a very long path for display by removing
|
|
|
|
# the left most parts and replacing them
|
|
|
|
# with a leading ...
|
|
|
|
#
|
|
|
|
# the first argument is the path
|
|
|
|
#
|
|
|
|
# the second argument is the maximum allowed
|
|
|
|
# length including the '/'s and ...
|
|
|
|
# http://hbfs.wordpress.com/2009/09/01/short-pwd-in-bash-prompts/
|
|
|
|
#
|
|
|
|
# + keep some left part of the path if asked
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_shorten_path()
|
2012-07-29 16:19:06 -04:00
|
|
|
{
|
2013-01-09 07:50:06 -05:00
|
|
|
if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 || -n "$PROMPT_DIRTRIM" ]] ; then
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2013-01-09 07:16:45 -05:00
|
|
|
echo "\\w"
|
|
|
|
else
|
2013-05-04 08:31:57 -04:00
|
|
|
print -P '%~'
|
2013-01-09 07:16:45 -05:00
|
|
|
fi
|
2012-08-16 09:16:48 -04:00
|
|
|
return
|
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2013-05-06 07:02:21 -04:00
|
|
|
local p="${PWD/#$HOME/~}"
|
2013-05-04 08:31:57 -04:00
|
|
|
local -i len=${#p}
|
|
|
|
local -i max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2013-05-04 08:31:57 -04:00
|
|
|
if (( len > max_len ))
|
2012-08-12 04:08:59 -04:00
|
|
|
then
|
2013-05-04 08:31:57 -04:00
|
|
|
# index of the directory to keep from the root
|
|
|
|
# (starts at 0 whith bash, 1 with zsh)
|
|
|
|
local -i keep=LP_PATH_KEEP-1
|
|
|
|
# the character that will replace the part of the path that is
|
|
|
|
# masked
|
|
|
|
local mask="$LP_MARK_SHORTEN_PATH"
|
|
|
|
local -i mask_len=${#mask}
|
2012-08-12 04:08:59 -04:00
|
|
|
# finds all the '/' in
|
|
|
|
# the path and stores their
|
|
|
|
# positions
|
|
|
|
#
|
2012-08-11 18:46:05 -04:00
|
|
|
local pos=()
|
2013-05-04 08:31:57 -04:00
|
|
|
local -i slashes=0
|
2012-08-11 18:46:05 -04:00
|
|
|
for ((i=0;i<len;i++))
|
|
|
|
do
|
2013-05-04 08:31:57 -04:00
|
|
|
if [[ "${p:i:1}" == / ]]
|
2012-08-11 18:46:05 -04:00
|
|
|
then
|
|
|
|
pos=(${pos[@]} $i)
|
2013-05-04 08:31:57 -04:00
|
|
|
let slashes++
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
pos=(${pos[@]} $len)
|
|
|
|
|
|
|
|
# we have the '/'s, let's find the
|
|
|
|
# left-most that doesn't break the
|
|
|
|
# length limit
|
|
|
|
#
|
2013-05-04 08:31:57 -04:00
|
|
|
local -i i=keep
|
|
|
|
if (( keep > slashes )) ; then
|
|
|
|
i=slashes
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
2013-05-04 08:31:57 -04:00
|
|
|
while (( len-pos[i] > max_len-mask_len ))
|
2012-08-11 18:46:05 -04:00
|
|
|
do
|
2013-05-04 08:31:57 -04:00
|
|
|
let i++
|
2012-08-11 18:46:05 -04:00
|
|
|
done
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2012-08-11 18:46:05 -04:00
|
|
|
# let us check if it's OK to
|
|
|
|
# print the whole thing
|
2012-07-29 16:19:06 -04:00
|
|
|
#
|
2013-05-04 08:31:57 -04:00
|
|
|
if (( pos[i] == 0 ))
|
2012-08-11 18:46:05 -04:00
|
|
|
then
|
|
|
|
# the path is shorter than
|
|
|
|
# the maximum allowed length,
|
2013-05-04 08:31:57 -04:00
|
|
|
# so no need for '…'
|
2012-08-11 18:46:05 -04:00
|
|
|
#
|
|
|
|
echo "$p"
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2013-05-04 08:31:57 -04:00
|
|
|
elif (( pos[i] == len ))
|
2012-08-11 18:46:05 -04:00
|
|
|
then
|
|
|
|
# constraints are broken because
|
|
|
|
# the maximum allowed size is smaller
|
|
|
|
# than the last part of the path, plus
|
|
|
|
# ' … '
|
|
|
|
#
|
2013-05-04 08:31:57 -04:00
|
|
|
echo "${p:0:pos[keep]+1}${mask}${p:len-max_len+mask_len}"
|
2012-08-11 18:46:05 -04:00
|
|
|
else
|
|
|
|
# constraints are satisfied, at least
|
|
|
|
# some parts of the path, plus ' … ', are
|
|
|
|
# shorter than the maximum allowed size
|
|
|
|
#
|
2013-05-04 08:31:57 -04:00
|
|
|
echo "${p:0:pos[keep]+1}${mask}${p:pos[i]}"
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
2012-08-12 04:08:59 -04:00
|
|
|
else
|
|
|
|
echo "$p"
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2013-05-04 08:31:57 -04:00
|
|
|
if (( len > max_len )); then
|
2013-05-04 10:54:00 -04:00
|
|
|
print -P "%-${LP_PATH_KEEP}~%${max_len}<${LP_MARK_SHORTEN_PATH}<%~%<<"
|
2012-08-12 04:51:29 -04:00
|
|
|
else
|
2013-05-04 10:54:00 -04:00
|
|
|
print -P '%~'
|
2012-08-12 04:51:29 -04:00
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-01-10 04:22:58 -05:00
|
|
|
# In bash shell, PROMPT_DIRTRIM is the number of directory to keep at the end
|
|
|
|
# of the displayed path (if "\w" is present in the PS1 var).
|
|
|
|
# liquidprompt can calculate this number under two condition, path shortening
|
|
|
|
# must be activated and PROMPT_DIRTRIM must be already set.
|
2013-01-09 07:50:06 -05:00
|
|
|
_lp_get_dirtrim() {
|
2013-01-10 04:12:35 -05:00
|
|
|
[[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] && echo 0 && return
|
2013-01-09 07:50:06 -05:00
|
|
|
|
2013-01-10 04:56:13 -05:00
|
|
|
local p="${PWD/$HOME/~}"
|
|
|
|
local len=${#p}
|
2013-01-09 07:50:06 -05:00
|
|
|
local max_len=$((${COLUMNS:-80}*$LP_PATH_LENGTH/100))
|
|
|
|
local PROMPT_DIRTRIM=0
|
|
|
|
|
2013-01-10 04:56:13 -05:00
|
|
|
if [[ "$((len))" -gt "$((max_len))" ]]; then
|
2013-01-09 07:50:06 -05:00
|
|
|
local i
|
|
|
|
|
2013-01-10 04:56:13 -05:00
|
|
|
for ((i=$len;i>=0;i--))
|
2013-01-09 07:50:06 -05:00
|
|
|
do
|
2013-01-10 04:56:13 -05:00
|
|
|
[[ $(($len-$i)) -gt $max_len ]] && break
|
|
|
|
[[ "${p:i:1}" == "/" ]] && PROMPT_DIRTRIM=$((PROMPT_DIRTRIM+1))
|
2013-01-09 07:50:06 -05:00
|
|
|
done
|
|
|
|
[[ "$((PROMPT_DIRTRIM))" -eq 0 ]] && PROMPT_DIRTRIM=1
|
|
|
|
fi
|
|
|
|
echo "$PROMPT_DIRTRIM"
|
|
|
|
}
|
|
|
|
|
2012-07-29 16:19:06 -04:00
|
|
|
# Display a ":"
|
|
|
|
# colored in green if user have write permission on the current directory
|
|
|
|
# colored in red if it have not.
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_permissions_color()
|
2012-07-29 16:19:06 -04:00
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
if [[ "$LP_ENABLE_PERM" != 1 ]]; then
|
|
|
|
echo : # without color
|
2012-07-29 16:19:06 -04:00
|
|
|
else
|
2012-08-16 09:34:03 -04:00
|
|
|
if [[ -w "${PWD}" ]]; then
|
|
|
|
echo "${LP_COLOR_WRITE}:${NO_COL}"
|
|
|
|
else
|
|
|
|
echo "${LP_COLOR_NOWRITE}:${NO_COL}"
|
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-01-03 10:44:15 -05:00
|
|
|
# Display the current Python virtual environnement, if available.
|
|
|
|
_lp_virtualenv()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_VIRTUALENV" != 1 ]] && return
|
2013-04-21 17:17:18 -04:00
|
|
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
|
|
|
echo "[${LP_COLOR_VIRTUALENV}$(basename $VIRTUAL_ENV)${NO_COL}]"
|
|
|
|
fi
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_JOBS" != 1 ]] && return
|
|
|
|
|
2012-08-13 14:40:36 -04:00
|
|
|
local running=$(( $(jobs -r | wc -l) ))
|
|
|
|
local stopped=$(( $(jobs -s | wc -l) ))
|
2013-03-14 17:41:09 -04:00
|
|
|
local n_screen=$(screen -ls 2> /dev/null | grep -c Detach)
|
2013-03-14 17:58:27 -04:00
|
|
|
local n_tmux=$(tmux list-sessions 2> /dev/null | grep -cv attached)
|
2013-03-14 17:41:09 -04:00
|
|
|
local detached=$(( $n_screen + $n_tmux ))
|
2012-08-10 08:28:18 -04:00
|
|
|
local m_detached="d"
|
|
|
|
local m_stop="z"
|
|
|
|
local m_run="&"
|
2013-03-14 17:41:09 -04:00
|
|
|
local ret=""
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2013-03-14 17:41:09 -04:00
|
|
|
if [[ $detached != "0" ]] ; then
|
|
|
|
ret="${ret}${LP_COLOR_JOB_D}${detached}${m_detached}${NO_COL}"
|
|
|
|
fi
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2013-03-14 17:41:09 -04:00
|
|
|
if [[ $running != "0" ]] ; then
|
|
|
|
if [[ $ret != "" ]] ; then ret="${ret}/"; fi
|
|
|
|
ret="${ret}${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}"
|
|
|
|
fi
|
2012-08-10 09:08:08 -04:00
|
|
|
|
2013-03-14 17:41:09 -04:00
|
|
|
if [[ $stopped != "0" ]] ; then
|
|
|
|
if [[ $ret != "" ]] ; then ret="${ret}/"; fi
|
|
|
|
ret="${ret}${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2013-03-14 17:41:09 -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
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_GIT" != 1 ]] && return
|
2013-03-12 15:00:36 -04:00
|
|
|
local gitdir
|
2013-04-20 22:59:46 -04:00
|
|
|
gitdir="$([ $(git ls-files . 2>/dev/null | wc -l) -gt 0 ] && git rev-parse --git-dir 2>/dev/null)"
|
2013-03-25 14:40:04 -04:00
|
|
|
[[ $? -ne 0 || ! $gitdir =~ (.*\/)?\.git.* ]] && return
|
2012-12-03 09:42:15 -05:00
|
|
|
local branch="$(git symbolic-ref HEAD 2>/dev/null)"
|
2013-03-12 15:47:52 -04:00
|
|
|
if [[ $? -ne 0 || -z "$branch" ]] ; then
|
|
|
|
# In detached head state, use commit instead
|
2013-05-16 13:12:42 -04:00
|
|
|
# No escape needed
|
|
|
|
git rev-parse --short HEAD 2>/dev/null
|
|
|
|
else
|
|
|
|
_lp_escape "${branch#refs/heads/}"
|
2013-03-12 15:47:52 -04:00
|
|
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_GIT" != 1 ]] && return
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(_lp_git_branch)"
|
2013-05-04 18:35:38 -04:00
|
|
|
if [[ -n "$branch" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2013-04-24 09:21:58 -04:00
|
|
|
local end="$NO_COL"
|
|
|
|
if git status 2>/dev/null | grep -q '\(# Untracked\)'; then
|
|
|
|
end="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED$end"
|
2012-08-16 08:08:07 -04:00
|
|
|
fi
|
|
|
|
|
2013-04-24 09:21:58 -04:00
|
|
|
if [[ -n "$(git stash list 2>/dev/null)" ]]; then
|
|
|
|
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
|
|
|
|
remote="$(git config --get branch.${branch}.remote 2>/dev/null)"
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local has_commit
|
2013-03-12 15:51:22 -04:00
|
|
|
has_commit=0
|
2013-04-24 09:21:58 -04:00
|
|
|
if [[ -n "$remote" ]] ; then
|
|
|
|
local remote_branch
|
|
|
|
remote_branch="$(git config --get branch.${branch}.merge)"
|
|
|
|
if [[ -n "$remote_branch" ]] ; then
|
2013-06-02 06:14:58 -04:00
|
|
|
has_commit="$(git rev-list --no-merges --count ${remote_branch/refs\/heads/refs\/remotes\/$remote}..HEAD 2>/dev/null)"
|
2013-04-24 09:21:58 -04:00
|
|
|
if [[ -z "$has_commit" ]] ; then
|
|
|
|
has_commit=0
|
|
|
|
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-06-02 06:14:58 -04:00
|
|
|
local shortstat="$(LANG=C git diff --shortstat 2>/dev/null)"
|
2013-05-14 18:33:28 -04:00
|
|
|
if [[ -n "$shortstat" ]] ; then
|
|
|
|
#has_lines=$(git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
|
2013-05-27 18:34:35 -04:00
|
|
|
local has_lines=${shortstat/*changed, /}
|
2013-05-25 14:38:15 -04:00
|
|
|
has_lines=${has_lines/ inser*, /\/-}
|
2013-05-14 18:33:28 -04:00
|
|
|
has_lines=${has_lines/ del*/}
|
2013-05-27 18:34:35 -04:00
|
|
|
[[ "$shortstat" = *insertion* ]] && has_lines="+${has_lines/ inser*/}" || has_lines="-$has_lines"
|
2013-05-14 18:33:28 -04:00
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$has_commit" -gt "0" ]] ; then
|
2012-08-04 13:52:24 -04:00
|
|
|
# Changes to commit and commits to push
|
2013-05-14 18:28:32 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})"
|
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
|
|
|
|
else
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$has_commit" -gt "0" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
# some commit(s) to push
|
2013-05-14 18:28:32 -04:00
|
|
|
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2013-05-14 18:28:32 -04:00
|
|
|
ret="${LP_COLOR_UP}${branch}" # nothing to commit or push
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
fi
|
2013-05-14 18:28:32 -04:00
|
|
|
echo -ne "$ret$end"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-07-07 03:32:29 -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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_HG" != 1 ]] && return
|
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-05-16 13:41:25 -04:00
|
|
|
[[ $? -eq 0 ]] && _lp_escape "$branch"
|
2013-03-13 10:58:56 -04:00
|
|
|
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_HG" != 1 ]] && return
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local branch
|
|
|
|
local ret
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(_lp_hg_branch)"
|
2013-05-04 18:35:38 -04:00
|
|
|
if [[ -n "$branch" ]] ; then
|
2013-03-13 13:31:26 -04:00
|
|
|
|
|
|
|
local has_untracked
|
|
|
|
has_untracked=$(hg status 2>/dev/null | grep '\(^\?\)' | wc -l)
|
|
|
|
if [[ -z "$has_untracked" ]] ; then
|
|
|
|
has_untracked=""
|
|
|
|
else
|
|
|
|
has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED"
|
|
|
|
fi
|
|
|
|
|
|
|
|
local has_commit
|
|
|
|
has_commit=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep '\(^changeset\:\)' | wc -l)
|
|
|
|
if [[ -z "$has_commit" ]] ; then
|
|
|
|
has_commit=0
|
|
|
|
fi
|
|
|
|
|
2012-08-13 14:40:36 -04:00
|
|
|
if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then
|
2013-03-13 13:31:26 -04:00
|
|
|
if [[ "$has_commit" -gt "0" ]] ; then
|
|
|
|
# some commit(s) to push
|
|
|
|
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}"
|
|
|
|
else
|
|
|
|
ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}" # nothing to commit or push
|
|
|
|
fi
|
2012-07-19 03:59:09 -04:00
|
|
|
else
|
2013-03-13 13:31:26 -04:00
|
|
|
local has_line
|
|
|
|
has_lines=$(hg diff --stat 2>/dev/null | tail -n 1 | awk 'FS=" " {printf("+%s/-%s\n", $4, $6)}')
|
|
|
|
if [[ "$has_commit" -gt "0" ]] ; then
|
|
|
|
# Changes to commit and commits to push
|
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}"
|
|
|
|
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
|
2012-08-10 08:40:50 -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
|
|
|
{
|
2012-08-21 16:03:42 -04:00
|
|
|
[[ "$LP_ENABLE_SVN" != 1 ]] && return
|
2012-08-17 02:32:00 -04:00
|
|
|
local root
|
|
|
|
local url
|
|
|
|
eval $(LANG=C LC_ALL=C svn info 2>/dev/null | sed -n 's/^URL: \(.*\)/url="\1"/p;s/^Repository Root: \(.*\)/root="\1"/p' )
|
2013-05-22 17:42:55 -04:00
|
|
|
[[ -z "$root" ]] && return
|
|
|
|
|
2012-08-17 02:32:00 -04:00
|
|
|
# Make url relative to root
|
|
|
|
url="${url:${#root}}"
|
|
|
|
if [[ "$url" == */trunk* ]] ; then
|
2013-03-13 17:49:23 -04:00
|
|
|
echo -n trunk
|
2012-08-17 02:32:00 -04:00
|
|
|
else
|
2013-05-22 17:42:55 -04:00
|
|
|
_lp_escape "$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$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
|
|
|
|
# (use $LP_SVN_STATUS_OPTS to define what that means with
|
|
|
|
# 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
|
|
|
{
|
2012-08-21 16:03:42 -04:00
|
|
|
[[ "$LP_ENABLE_SVN" != 1 ]] && 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)"
|
|
|
|
if [[ -n "$branch" ]] ; then
|
2012-08-13 17:15:24 -04:00
|
|
|
local commits
|
2013-01-31 04:14:13 -05:00
|
|
|
changes=$(( $(svn status $LP_SVN_STATUS_OPTIONS | grep -c -v "?") ))
|
|
|
|
if [[ $changes -eq 0 ]] ; then
|
2012-08-17 03:52:28 -04:00
|
|
|
echo "${LP_COLOR_UP}${branch}${NO_COL}"
|
2012-07-19 04:49:07 -04:00
|
|
|
else
|
2013-01-31 04:14:13 -05:00
|
|
|
echo "${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()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_FOSSIL" != 1 ]] && return
|
2013-01-12 10:29:55 -05:00
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(fossil status 2>/dev/null | grep tags: | cut -c17-)"
|
2013-01-12 10:29:55 -05:00
|
|
|
if [[ -n "$branch" ]] ; then
|
2013-05-16 13:41:25 -04:00
|
|
|
_lp_escape "$branch"
|
2013-01-12 10:29:55 -05:00
|
|
|
else
|
2013-03-13 10:58:56 -04:00
|
|
|
if fossil info &>/dev/null ; then
|
|
|
|
echo "no-tag"
|
|
|
|
fi
|
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()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_FOSSIL" != 1 ]] && return
|
|
|
|
|
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(_lp_fossil_branch)"
|
2012-12-29 08:40:54 -05:00
|
|
|
|
2013-05-04 18:35:38 -04:00
|
|
|
if [[ -n "$branch" ]] ; then
|
2013-03-13 10:58:56 -04:00
|
|
|
local C2E # Modified files (added or edited)
|
|
|
|
local C2D # Deleted files
|
|
|
|
local C2A # Extras files
|
2013-05-20 10:29:13 -04:00
|
|
|
local C2AA # Added files
|
|
|
|
local PLUSLINE # Added lines
|
|
|
|
local MINUSLINE # Deleted lines
|
2013-03-13 10:58:56 -04:00
|
|
|
local ret
|
|
|
|
C2E=$(fossil changes | wc -l)
|
|
|
|
C2A=$(fossil extras | wc -l)
|
2013-05-20 10:29:13 -04:00
|
|
|
PLUSLINE=$(fossil diff | egrep '^\+[^+].+$' | wc -l)
|
|
|
|
MINUSLINE=$(fossil diff | egrep '^-[^-].+$' | wc -l)
|
2013-03-13 10:58:56 -04:00
|
|
|
ret=""
|
|
|
|
|
2013-05-20 10:29:13 -04:00
|
|
|
C2AA=`fossil changes | grep ADDED | wc -l`
|
|
|
|
if [[ $C2AA -gt 0 ]] ; then
|
|
|
|
# We count the line "à la" git
|
|
|
|
local ADDFILE
|
|
|
|
local FILE
|
|
|
|
ADDFILE=`fossil changes | grep ADDED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2`
|
|
|
|
for FILE in $ADDFILE ; do
|
|
|
|
PLULI=$(wc -l $FILE | cut -d" " -f1)
|
|
|
|
let PLUSLINE=$PLUSLINE+$PLULI
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $PLUSLINE -gt 0 ]] ; then
|
|
|
|
ret+="+$PLUSLINE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
C2D=`fossil changes | grep DELETED | wc -l`
|
|
|
|
if [[ $C2D -gt 0 ]] ; then
|
|
|
|
# We count the line "à la" git
|
|
|
|
local DELFILE
|
|
|
|
local FILE
|
|
|
|
DELFILE=`fossil changes | grep DELETED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2`
|
|
|
|
for FILE in $DELFILE ; do
|
|
|
|
MINLI=$(wc -l $FILE | cut -d" " -f1)
|
|
|
|
let MINUSLINE=$MINUSLINE+$MINLI
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $MINUSLINE -gt 0 ]] ; then
|
2013-03-13 10:58:56 -04:00
|
|
|
if [[ "$ret" = "" ]] ; then
|
2013-05-20 10:29:13 -04:00
|
|
|
ret+="-$MINUSLINE"
|
2013-03-13 10:58:56 -04:00
|
|
|
else
|
2013-05-20 10:29:13 -04:00
|
|
|
ret+="/-$MINUSLINE"
|
2013-03-13 10:58:56 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-05-20 10:29:13 -04:00
|
|
|
if [[ "$C2E" -gt 0 ]] ; then
|
|
|
|
ret+=" in $C2E"
|
|
|
|
fi
|
|
|
|
|
2013-03-13 10:58:56 -04:00
|
|
|
if [[ "$C2A" -gt 0 ]] ; then
|
|
|
|
C2A="$LP_MARK_UNTRACKED"
|
|
|
|
else
|
|
|
|
C2A=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$ret" != "" ]] ; then
|
|
|
|
ret="(${LP_COLOR_DIFF}$ret${NO_COL})"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [[ "$branch" = "no-tag" ]] ; then
|
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}"
|
|
|
|
else
|
2013-01-02 16:54:23 -05:00
|
|
|
if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then
|
2013-01-05 17:03:26 -05:00
|
|
|
# All is up-to-date
|
2013-03-13 10:58:56 -04:00
|
|
|
branch="${LP_COLOR_UP}$branch$C2A${NO_COL}"
|
2013-01-02 16:54:23 -05:00
|
|
|
else
|
2013-01-05 17:03:26 -05:00
|
|
|
# There're some changes to commit
|
2013-03-13 10:58:56 -04:00
|
|
|
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
|
2013-01-02 16:54:23 -05:00
|
|
|
fi
|
2013-03-13 10:58:56 -04:00
|
|
|
fi
|
2013-05-16 13:41:25 -04:00
|
|
|
_lp_escape "$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()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_BZR" != 1 ]] && return
|
2013-03-13 10:58:56 -04:00
|
|
|
local branch
|
2013-06-02 06:14:58 -04:00
|
|
|
branch="$(bzr nick 2> /dev/null)"
|
2013-01-17 11:20:15 -05:00
|
|
|
[[ $? -ne 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()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_BZR" != 1 ]] && return
|
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)"
|
2013-05-10 19:15:11 -04:00
|
|
|
[[ $? -ne 0 ]] && return
|
2013-01-17 11:20:15 -05:00
|
|
|
local tuple=($output)
|
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]}
|
2013-01-17 11:20:15 -05:00
|
|
|
|
2013-05-04 18:35:38 -04:00
|
|
|
if [[ -n "$branch" ]] ; then
|
2013-01-17 11:20:15 -05:00
|
|
|
if [[ "$clean" -eq 0 ]] ; then
|
|
|
|
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
|
|
|
|
echo -ne "$ret"
|
|
|
|
}
|
|
|
|
|
2012-12-28 20:42:29 -05:00
|
|
|
|
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
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_battery()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2013-05-12 17:14:06 -04:00
|
|
|
[[ "$LP_ENABLE_BATT" != 1 ]] && return 4
|
2012-08-13 17:15:24 -04:00
|
|
|
local acpi
|
|
|
|
acpi="$(acpi --battery 2>/dev/null)"
|
2013-01-08 18:47:05 -05:00
|
|
|
# Extract the battery load value in percent
|
|
|
|
# First, remove the beginning of the line...
|
|
|
|
local bat="${acpi#Battery *, }"
|
|
|
|
bat="${bat%%%*}" # remove everything starting at '%'
|
2012-08-12 06:13:47 -04:00
|
|
|
|
|
|
|
if [[ -z "${bat}" ]] ; then
|
|
|
|
# not battery level found
|
|
|
|
return 4
|
|
|
|
|
|
|
|
# discharging
|
|
|
|
elif [[ "$acpi" == *"Discharging"* ]] ; then
|
|
|
|
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then
|
|
|
|
# under threshold
|
|
|
|
echo -n "${bat}"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
# above threshold
|
|
|
|
echo -n "${bat}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# charging
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-08-12 06:13:47 -04:00
|
|
|
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then
|
|
|
|
# under threshold
|
|
|
|
echo -n "${bat}"
|
|
|
|
return 2
|
|
|
|
else
|
|
|
|
# above threshold
|
|
|
|
echo -n "${bat}"
|
|
|
|
return 3
|
|
|
|
fi
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_BATT" != 1 ]] && return
|
|
|
|
|
2012-08-17 12:10:11 -04:00
|
|
|
local mark=$LP_MARK_BATTERY
|
|
|
|
local chargingmark=$LP_MARK_ADAPTER
|
2012-08-12 06:13:47 -04:00
|
|
|
local bat
|
|
|
|
local 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
|
|
|
|
2012-08-12 06:13:47 -04:00
|
|
|
if [[ $ret == 4 || $bat == 100 ]] ; then
|
|
|
|
# no battery support or battery full: nothing displayed
|
|
|
|
return
|
|
|
|
elif [[ $ret == 3 && $bat != 100 ]] ; then
|
|
|
|
# charging and above threshold and not 100%
|
2012-08-13 04:02:10 -04:00
|
|
|
# green ⏚
|
2012-08-14 08:35:20 -04:00
|
|
|
echo -ne "${LP_COLOR_CHARGING_ABOVE}$chargingmark${NO_COL}"
|
2012-08-12 06:13:47 -04:00
|
|
|
return
|
|
|
|
elif [[ $ret == 2 ]] ; then
|
|
|
|
# charging but under threshold
|
2012-08-13 04:02:10 -04:00
|
|
|
# yellow ⏚
|
2012-08-14 08:35:20 -04:00
|
|
|
echo -ne "${LP_COLOR_CHARGING_UNDER}$chargingmark${NO_COL}"
|
2012-08-12 06:13:47 -04:00
|
|
|
return
|
|
|
|
elif [[ $ret == 1 ]] ; then
|
|
|
|
# discharging but above threshold
|
2012-08-13 04:02:10 -04:00
|
|
|
# yellow ⌁
|
2012-08-14 08:35:20 -04:00
|
|
|
echo -ne "${LP_COLOR_DISCHARGING_ABOVE}$mark${NO_COL}"
|
2012-08-12 06:13:47 -04:00
|
|
|
return
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-08-12 06:13:47 -04:00
|
|
|
# discharging and under threshold
|
|
|
|
elif [[ "$bat" != "" ]] ; then
|
2012-08-14 08:35:20 -04:00
|
|
|
ret="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2013-03-13 07:30:41 -04:00
|
|
|
if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then
|
|
|
|
if [[ ${bat} -le 100 ]] && [[ ${bat} -gt 80 ]] ; then # -20
|
|
|
|
ret="${ret}${LP_COLORMAP_1}"
|
|
|
|
elif [[ ${bat} -le 80 ]] && [[ ${bat} -gt 65 ]] ; then # -15
|
|
|
|
ret="${ret}${LP_COLORMAP_2}"
|
|
|
|
elif [[ ${bat} -le 65 ]] && [[ ${bat} -gt 50 ]] ; then # -15
|
|
|
|
ret="${ret}${LP_COLORMAP_3}"
|
|
|
|
elif [[ ${bat} -le 50 ]] && [[ ${bat} -gt 40 ]] ; then # -10
|
|
|
|
ret="${ret}${LP_COLORMAP_4}"
|
|
|
|
elif [[ ${bat} -le 40 ]] && [[ ${bat} -gt 30 ]] ; then # …
|
|
|
|
ret="${ret}${LP_COLORMAP_5}"
|
|
|
|
elif [[ ${bat} -le 30 ]] && [[ ${bat} -gt 20 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_6}"
|
|
|
|
elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_7}"
|
|
|
|
elif [[ ${bat} -le 10 ]] && [[ ${bat} -gt 5 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_8}"
|
|
|
|
elif [[ ${bat} -le 5 ]] && [[ ${bat} -gt 0 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_9}"
|
|
|
|
else
|
|
|
|
# for debugging purpose
|
|
|
|
ret="${ret}${LP_COLORMAP_0}"
|
|
|
|
fi
|
|
|
|
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2013-03-13 07:30:41 -04:00
|
|
|
ret="${ret}${bat}%"
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2013-03-13 07:30:41 -04:00
|
|
|
ret="${ret}${bat}%%"
|
|
|
|
fi
|
|
|
|
fi # LP_PERCENTS_ALWAYS
|
|
|
|
echo -ne "${ret}${NO_COL}"
|
|
|
|
fi # ret
|
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
|
|
|
|
local -i scale=${2:-100}
|
|
|
|
# Transform the value to a 0..100 scale
|
|
|
|
local -i value=100*$1/scale
|
|
|
|
if (( value < 50 )); then
|
|
|
|
if (( value < 30 )); then
|
|
|
|
if (( value < 10 )); then
|
2013-05-13 14:40:04 -04:00
|
|
|
echo -ne "${LP_COLORMAP_0}"
|
2013-06-11 15:03:10 -04:00
|
|
|
elif (( value < 20 )); then
|
2013-05-13 14:40:04 -04:00
|
|
|
echo -ne "${LP_COLORMAP_1}"
|
|
|
|
else # 40..59
|
|
|
|
echo -ne "${LP_COLORMAP_2}"
|
|
|
|
fi
|
2013-06-11 15:03:10 -04:00
|
|
|
elif (( value < 40 )); then
|
2013-05-13 14:40:04 -04:00
|
|
|
echo -ne "${LP_COLORMAP_3}"
|
|
|
|
else # 80..99
|
|
|
|
echo -ne "${LP_COLORMAP_4}"
|
|
|
|
fi
|
2013-06-11 15:03:10 -04:00
|
|
|
elif (( value < 80 )); then
|
|
|
|
if (( value < 60 )); then
|
2013-05-13 14:40:04 -04:00
|
|
|
echo -ne "${LP_COLORMAP_5}"
|
2013-06-11 15:03:10 -04:00
|
|
|
elif (( value < 70 )); then
|
2013-05-13 14:40:04 -04:00
|
|
|
echo -ne "${LP_COLORMAP_6}"
|
|
|
|
else
|
|
|
|
echo -ne "${LP_COLORMAP_7}"
|
|
|
|
fi
|
2013-06-11 15:03:10 -04:00
|
|
|
elif (( value < 90 )) ; then
|
2013-04-21 10:16:06 -04:00
|
|
|
echo -ne "${LP_COLORMAP_8}"
|
2013-06-11 15:03:10 -04:00
|
|
|
else # (( value >= 90 ))
|
2013-04-21 10:16:06 -04:00
|
|
|
echo -ne "${LP_COLORMAP_9}"
|
|
|
|
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.
|
|
|
|
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_LOAD" != 1 ]] && return
|
|
|
|
|
2013-06-02 06:14:58 -04:00
|
|
|
local tmp="$(_lp_cpu_load)"
|
2013-05-13 19:15:04 -04:00
|
|
|
tmp=${tmp/./} # Remove '.'
|
|
|
|
tmp=${tmp#0} # Remove leading '0'
|
|
|
|
tmp=${tmp#0} # Remove leading '0', again (ex: 0.09)
|
|
|
|
local -i load=${tmp:-0}/$_lp_CPUNUM
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2013-05-13 19:15:04 -04:00
|
|
|
if (( load > $LP_LOAD_THRESHOLD )); then
|
2013-06-07 06:05:31 -04:00
|
|
|
local ret="$(_lp_color_map $load 200)${LP_MARK_LOAD}"
|
2013-03-13 07:30:41 -04:00
|
|
|
|
2013-05-13 19:15:04 -04:00
|
|
|
if [[ "$LP_PERCENTS_ALWAYS" == 1 ]]; then
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2013-03-13 07:30:41 -04:00
|
|
|
ret="${ret}$load%"
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2013-03-13 07:30:41 -04:00
|
|
|
ret="${ret}$load%%"
|
|
|
|
fi
|
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
|
|
|
|
2013-04-24 03:48:18 -04:00
|
|
|
_lp_temp_sensors() {
|
2013-05-20 12:39:50 -04:00
|
|
|
# Return the hottest system temperature we get through the sensors command
|
2013-04-21 10:16:06 -04:00
|
|
|
local temperature=0
|
2013-06-10 03:58:29 -04:00
|
|
|
for i in $(sensors |
|
|
|
|
sed -n -r "s/^(CPU|SYS|MB|Core|temp).*: *\+([0-9]*)\..°.*/\2/p"); do
|
2013-05-20 12:39:50 -04:00
|
|
|
if [[ $i -gt $temperature ]]; then
|
|
|
|
temperature=$i
|
|
|
|
fi
|
2013-04-21 10:16:06 -04:00
|
|
|
done
|
2013-05-20 12:39:50 -04:00
|
|
|
echo -ne "$temperature"
|
2013-04-24 03:48:18 -04:00
|
|
|
}
|
|
|
|
|
2013-06-11 16:06:20 -04:00
|
|
|
# Will set _LP_TEMP_FUNCTION so the temperature monitoring feature use an
|
|
|
|
# available command. _LP_TEMP_FUNCTION should return only a numeric value
|
2013-04-24 03:48:18 -04:00
|
|
|
if [[ "$LP_ENABLE_TEMP" = 1 ]]; then
|
|
|
|
if command -v sensors >/dev/null; then
|
2013-06-11 16:06:20 -04:00
|
|
|
_LP_TEMP_FUNCTION=_lp_temp_sensors
|
2013-04-24 03:48:18 -04:00
|
|
|
# elif command -v the_command_you_want_to_use; then
|
2013-06-11 16:06:20 -04:00
|
|
|
# _LP_TEMP_FUNCTION=your_function
|
2013-04-24 03:48:18 -04:00
|
|
|
else
|
|
|
|
LP_ENABLE_TEMP=0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
_lp_temperature() {
|
2013-06-11 16:06:20 -04:00
|
|
|
# Will display the numeric value as we got it through the _LP_TEMP_FUNCTION
|
2013-04-24 03:48:18 -04:00
|
|
|
# and colorize it through _lp_color_map.
|
|
|
|
[[ "$LP_ENABLE_TEMP" != 1 ]] && return
|
|
|
|
|
2013-06-11 16:06:20 -04:00
|
|
|
local temperature="$($_LP_TEMP_FUNCTION)"
|
2013-04-21 10:16:06 -04:00
|
|
|
if [[ $temperature -ge $LP_TEMP_THRESHOLD ]]; then
|
2013-06-07 06:05:31 -04:00
|
|
|
echo -ne "${LP_MARK_TEMP}$(_lp_color_map $temperature 120)$temperature°${NO_COL}"
|
2013-04-21 10:16:06 -04:00
|
|
|
fi
|
|
|
|
}
|
2012-07-19 05:21:18 -04:00
|
|
|
|
|
|
|
##########
|
|
|
|
# DESIGN #
|
|
|
|
##########
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
# Remove colors from the computed prompt
|
2013-04-28 12:10:08 -04:00
|
|
|
case "$LP_OS" in
|
2013-06-02 06:14:58 -04:00
|
|
|
Linux|FreeBSD|SunOS) local pst="$(echo $1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" ;;
|
|
|
|
Darwin) local pst="$(echo $1 | sed -E "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" ;;
|
2013-04-28 12:10:08 -04:00
|
|
|
esac
|
|
|
|
|
2013-01-10 11:18:45 -05:00
|
|
|
|
|
|
|
# Remove escape sequences
|
2013-01-11 08:18:24 -05:00
|
|
|
# FIXME check the zsh compatibility
|
|
|
|
# pst=$(echo $pst | sed "s,\\\\\\[\|\\\\\\],,g")
|
2013-06-02 06:14:58 -04:00
|
|
|
local op="$(printf "%q" "$_LP_OPEN_ESC")"
|
|
|
|
local cl="$(printf "%q" "$_LP_CLOSE_ESC")"
|
|
|
|
pst="$(echo $pst | sed "s,$op\|$cl,,g")" # replace all open _or_ close tags with nothing
|
2013-01-10 11:18:45 -05:00
|
|
|
|
|
|
|
echo -n "$pst"
|
|
|
|
}
|
|
|
|
|
|
|
|
_lp_title()
|
|
|
|
{
|
2013-01-11 08:18:24 -05:00
|
|
|
[[ "$LP_ENABLE_TITLE" != "1" ]] && return
|
2013-01-10 11:18:45 -05:00
|
|
|
|
|
|
|
# Get the current computed prompt as pure text
|
2013-06-02 06:14:58 -04:00
|
|
|
local txt="$(_lp_as_text "$1")"
|
2013-01-10 11:18:45 -05:00
|
|
|
|
|
|
|
# Use it in the window's title
|
|
|
|
# Escapes whill tells bash to ignore the non-printing control characters when calculating the width of the prompt.
|
|
|
|
# Otherwise line editing commands will mess the cursor positionning
|
2013-03-07 19:59:06 -05:00
|
|
|
case "$TERM" in
|
|
|
|
screen*)
|
2013-03-08 05:48:21 -05:00
|
|
|
[[ "$LP_ENABLE_SCREEN_TITLE" != "1" ]] && return
|
2013-03-07 20:12:39 -05:00
|
|
|
local title="${LP_SCREEN_TITLE_OPEN}${txt}${LP_SCREEN_TITLE_CLOSE}"
|
2013-03-07 19:59:06 -05:00
|
|
|
;;
|
2013-03-13 18:37:43 -04:00
|
|
|
linux*)
|
|
|
|
local title=""
|
|
|
|
;;
|
2013-03-08 05:48:21 -05:00
|
|
|
*)
|
|
|
|
local title="${_LP_OPEN_ESC}${LP_TITLE_OPEN}${txt}${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
|
|
|
|
;;
|
2013-03-07 19:59:06 -05:00
|
|
|
esac
|
2013-01-10 11:18:45 -05:00
|
|
|
echo -n "${title}"
|
|
|
|
}
|
|
|
|
|
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-04-17 08:12:17 -04:00
|
|
|
if [[ -n "$LP_MARK_DEFAULT" ]]; then
|
|
|
|
mark=$LP_MARK_DEFAULT
|
2013-05-04 18:11:18 -04:00
|
|
|
elif $_LP_SHELL_zsh; then
|
2012-08-16 08:11:52 -04:00
|
|
|
mark="%(!.#.%%)"
|
2013-04-17 08:12:17 -04:00
|
|
|
else
|
|
|
|
mark="\\\$"
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
2013-01-23 09:44:42 -05:00
|
|
|
if [[ "$1" == "git" ]]; then
|
2012-08-16 11:56:36 -04:00
|
|
|
mark=$LP_MARK_GIT
|
2013-03-20 08:56:44 -04:00
|
|
|
elif [[ "$1" == "git-svn" ]]; then
|
|
|
|
mark="$LP_MARK_GIT$LP_MARK_SVN"
|
2013-01-23 09:44:42 -05:00
|
|
|
elif [[ "$1" == "hg" ]]; then
|
2012-08-16 11:56:36 -04:00
|
|
|
mark=$LP_MARK_HG
|
2013-01-23 09:44:42 -05:00
|
|
|
elif [[ "$1" == "svn" ]]; then
|
2012-08-16 11:56:36 -04:00
|
|
|
mark=$LP_MARK_SVN
|
2013-01-23 09:44:42 -05:00
|
|
|
elif [[ "$1" == "fossil" ]]; then
|
2012-12-28 20:42:29 -05:00
|
|
|
mark=$LP_MARK_FOSSIL
|
2013-01-23 09:44:42 -05:00
|
|
|
elif [[ "$1" == "bzr" ]]; then
|
2013-01-17 11:20:15 -05:00
|
|
|
mark=$LP_MARK_BZR
|
2013-04-22 13:07:34 -04:00
|
|
|
elif [[ "$1" == "disabled" ]]; then
|
|
|
|
mark=$LP_MARK_DISABLED
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2013-06-11 16:23:26 -04:00
|
|
|
echo -ne "${LP_COLOR_MARK}${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
|
|
|
{
|
2013-05-04 18:34:03 -04:00
|
|
|
[[ -n "$1" ]] && echo -n "$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
|
|
|
{
|
2013-05-04 18:34:03 -04:00
|
|
|
[[ -n "$1" ]] && echo -n " $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
|
|
|
{
|
2013-05-04 18:34:03 -04:00
|
|
|
[[ -n "$1" ]] && echo -n " $1 "
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
|
|
|
|
2012-08-17 09:47:44 -04:00
|
|
|
###################
|
|
|
|
# CURRENT TIME #
|
|
|
|
###################
|
2013-04-20 15:51:55 -04:00
|
|
|
_lp_time_analog()
|
|
|
|
{
|
|
|
|
# get the date as "hours(12) minutes" in a single call
|
|
|
|
# make a bash array with it
|
2013-06-02 05:02:34 -04:00
|
|
|
local -a d
|
|
|
|
d=( $(date "+%I %M") )
|
2013-04-20 15:51:55 -04:00
|
|
|
# separate hours and minutes
|
2013-06-02 05:02:34 -04:00
|
|
|
local -i hour=${d[_LP_FIRST_INDEX+0]#0} # no leading 0
|
|
|
|
local -i min=${d[_LP_FIRST_INDEX+1]#0}
|
2013-04-20 15:51:55 -04:00
|
|
|
|
|
|
|
# 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
|
|
|
|
#
|
2013-04-21 18:07:45 -04:00
|
|
|
|
2013-06-02 05:02:34 -04:00
|
|
|
local -a plain
|
|
|
|
plain=(🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛 )
|
|
|
|
local -a half
|
|
|
|
half=(🕜 🕝 🕞 🕟 🕠 🕡 🕢 🕣 🕤 🕥 🕦 🕧 )
|
2013-04-21 18:07:45 -04:00
|
|
|
|
|
|
|
# array index starts at 0
|
2013-05-04 16:50:49 -04:00
|
|
|
local -i hi=hour-1
|
2013-04-21 18:07:45 -04:00
|
|
|
|
|
|
|
# add a space for correct alignment
|
2013-05-04 16:50:49 -04:00
|
|
|
if (( min < 15 )) ; then
|
|
|
|
echo -n "${plain[hi]} "
|
|
|
|
elif (( min < 45 )) ; then
|
|
|
|
echo -n "${half[hi]} "
|
2013-04-21 18:07:45 -04:00
|
|
|
else
|
2013-05-04 16:50:49 -04:00
|
|
|
echo -n "${plain[hi+1]} "
|
2013-04-21 18:07:45 -04:00
|
|
|
fi
|
2013-04-20 15:51:55 -04:00
|
|
|
}
|
|
|
|
|
2012-08-17 09:47:44 -04:00
|
|
|
_lp_time()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_TIME" != 1 ]] && return
|
2013-04-20 15:51:55 -04:00
|
|
|
if [[ "$LP_TIME_ANALOG" != 1 ]]; then
|
2013-05-04 16:58:12 -04:00
|
|
|
echo -n "${LP_COLOR_TIME}${_LP_TIME_SYMBOL}${NO_COL}"
|
2013-04-20 15:51:55 -04:00
|
|
|
else
|
2013-05-04 16:58:12 -04:00
|
|
|
echo -n "${LP_COLOR_TIME}"
|
2013-05-04 16:50:49 -04:00
|
|
|
_lp_time_analog
|
2013-05-04 16:58:12 -04:00
|
|
|
echo -n "${NO_COL}"
|
2013-04-20 15:51:55 -04:00
|
|
|
fi
|
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
|
|
|
|
LP_ERR= # Hidden
|
|
|
|
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)
|
|
|
|
local IFS="$(echo -e ' \t')
|
|
|
|
" # space, tab, LF
|
|
|
|
|
2013-01-23 13:00:26 -05:00
|
|
|
# execute the old prompt if not on Mac OS X (Mountain) Lion
|
|
|
|
case "$LP_OS" in
|
|
|
|
Linux|FreeBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;;
|
|
|
|
Darwin)
|
2013-03-20 08:56:44 -04:00
|
|
|
case "$(LP_DWIN_KERNEL_REL_VER)" in
|
2013-01-23 13:00:26 -05:00
|
|
|
11|12) update_terminal_cwd ;;
|
|
|
|
*) $LP_OLD_PROMPT_COMMAND ;;
|
|
|
|
esac ;;
|
|
|
|
esac
|
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)")"
|
|
|
|
LP_TIME="$(_lp_sr "$(_lp_time)")"
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# in main prompt: no space
|
2013-01-25 05:48:03 -05:00
|
|
|
LP_PROXY="$(_lp_proxy)"
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# right of main prompt: space at left
|
2013-06-02 06:14:58 -04:00
|
|
|
LP_VENV="$(_lp_sl "$(_lp_virtualenv)")"
|
2013-04-22 13:07:34 -04:00
|
|
|
# if change of working directory
|
2013-01-23 12:17:24 -05:00
|
|
|
if [[ "$LP_OLD_PWD" != "$PWD" ]]; then
|
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
|
2013-06-02 06:14:58 -04:00
|
|
|
LP_PERM="$(_lp_permissions_color)"
|
|
|
|
LP_PWD="$(_lp_shorten_path)"
|
|
|
|
[[ -n "$PROMPT_DIRTRIM" ]] && PROMPT_DIRTRIM="$(_lp_get_dirtrim)"
|
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
|
|
|
|
# If this is a git-svn repository
|
|
|
|
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
|
|
|
|
|
|
|
|
if [[ -z "$LP_VCS_TYPE" ]] ; then
|
|
|
|
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
|
2013-06-02 06:14:58 -04:00
|
|
|
LP_MARK="$(_lp_sb "$(_lp_smart_mark $LP_VCS_TYPE)")"
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2013-06-11 16:23:26 -04:00
|
|
|
# The color is different if user is root
|
|
|
|
LP_PWD="${LP_COLOR_PATH}${LP_PWD}${NO_COL}"
|
|
|
|
|
2013-01-23 12:17:24 -05:00
|
|
|
LP_OLD_PWD="$PWD"
|
|
|
|
|
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
|
|
|
|
|
2013-03-12 17:14:09 -04:00
|
|
|
if [[ -f "$LP_PS1_FILE" ]]; then
|
|
|
|
source "$LP_PS1_FILE"
|
|
|
|
fi
|
2013-03-12 16:02:28 -04:00
|
|
|
|
2012-08-10 09:46:44 -04:00
|
|
|
if [[ -z $LP_PS1 ]] ; then
|
2013-01-10 11:18:45 -05:00
|
|
|
# add title escape time, jobs, load and battery
|
2013-05-04 10:41:07 -04:00
|
|
|
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_TEMP}${LP_JOBS}"
|
2012-08-10 09:46:44 -04:00
|
|
|
# add user, host and permissions colon
|
2013-05-04 10:04:51 -04:00
|
|
|
PS1="${PS1}${LP_BRACKET_OPEN}${LP_USER}${LP_HOST}${LP_PERM}"
|
2012-07-19 08:17:32 -04:00
|
|
|
|
2013-06-11 16:37:14 -04:00
|
|
|
PS1="${PS1}${LP_PWD}${LP_BRACKET_CLOSE}${LP_VENV}${LP_PROXY}"
|
|
|
|
|
2012-08-10 09:46:44 -04:00
|
|
|
# if not root
|
|
|
|
if [[ "$EUID" -ne "0" ]]
|
|
|
|
then
|
|
|
|
# add VCS infos
|
2013-01-23 09:44:42 -05:00
|
|
|
PS1="${PS1}${LP_VCS}"
|
2012-08-10 09:46:44 -04:00
|
|
|
else
|
2013-01-04 06:13:00 -05:00
|
|
|
# do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT)
|
2013-01-23 12:17:24 -05:00
|
|
|
[[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && PS1="${PS1}${LP_VCS}"
|
2012-08-10 09:46:44 -04:00
|
|
|
fi
|
2013-06-11 16:37:14 -04:00
|
|
|
|
2012-08-10 09:46:44 -04:00
|
|
|
# add return code and prompt mark
|
2013-04-22 15:16:56 -04:00
|
|
|
PS1="${PS1}${LP_ERR}${LP_MARK}${LP_PS1_POSTFIX}"
|
2012-08-10 09:46:44 -04:00
|
|
|
|
2013-01-10 11:18:45 -05:00
|
|
|
# "invisible" parts
|
|
|
|
# Get the current prompt on the fly and make it a title
|
2013-06-02 06:14:58 -04:00
|
|
|
LP_TITLE="$(_lp_title "$PS1")"
|
2013-01-10 11:18:45 -05:00
|
|
|
|
|
|
|
# Insert it in the prompt
|
|
|
|
PS1="${LP_TITLE}${PS1}"
|
|
|
|
|
2012-08-10 09:46:44 -04:00
|
|
|
# Glue the bash prompt always go to the first column.
|
|
|
|
# Avoid glitches after interrupting a command with Ctrl-C
|
|
|
|
# Does not seem to be necessary anymore?
|
|
|
|
#PS1="\[\033[G\]${PS1}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-08-10 09:46:44 -04:00
|
|
|
PS1=$LP_PS1
|
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
|
|
|
|
2012-08-04 13:05:34 -04:00
|
|
|
# Activate the liquid prompt
|
|
|
|
prompt_on()
|
|
|
|
{
|
2012-08-07 15:29:44 -04:00
|
|
|
# if liquidprompt has not been already set
|
|
|
|
if [[ -z "$LP_LIQUIDPROMPT" ]] ; then
|
|
|
|
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"
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2012-08-11 18:46:05 -04:00
|
|
|
LP_OLD_PROMPT_COMMAND="$precmd"
|
|
|
|
fi
|
|
|
|
fi
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2012-08-16 14:18:29 -04:00
|
|
|
PROMPT_COMMAND=_lp_set_prompt
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2012-08-11 18:46:05 -04:00
|
|
|
function precmd {
|
2012-08-16 14:18:29 -04:00
|
|
|
_lp_set_prompt
|
2012-08-11 18:46:05 -04:00
|
|
|
}
|
2012-08-07 15:29:44 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Keep in mind that LP has been sourced
|
|
|
|
# (to avoid recursive prompt command).
|
|
|
|
LP_LIQUIDPROMPT=1
|
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
|
2012-08-11 18:46:05 -04:00
|
|
|
PROMPT_COMMAND=$LP_OLD_PROMPT_COMMAND
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2012-08-11 18:46:05 -04:00
|
|
|
precmd=$LP_OLD_PROMPT_COMMAND
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
PS1="\$ "
|
2013-05-04 18:11:18 -04:00
|
|
|
if $_LP_SHELL_bash; then
|
2012-08-11 18:46:05 -04:00
|
|
|
PROMPT_COMMAND=$LP_OLD_PROMPT_COMMAND
|
2013-05-04 18:11:18 -04:00
|
|
|
else # zsh
|
2012-08-11 18:46:05 -04:00
|
|
|
precmd=$LP_OLD_PROMPT_COMMAND
|
|
|
|
fi
|
2012-08-11 04:20:37 -04:00
|
|
|
}
|
|
|
|
|
2012-08-04 13:05:34 -04:00
|
|
|
# By default, sourcing liquidprompt.bash will activate the liquid prompt
|
|
|
|
prompt_on
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-08-14 18:21:21 -04:00
|
|
|
# Cleaning of variable that are not needed at runtime
|
|
|
|
unset LP_OS
|
|
|
|
|
2012-08-14 09:11:48 -04:00
|
|
|
# vim: set et sts=4 sw=4 tw=120 ft=sh:
|