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 #
|
|
|
|
###########
|
|
|
|
|
|
|
|
# nojhan <nojhan@gmail.com> # Main author.
|
|
|
|
# Aurelien Requiem <aurelien@requiem.fr> # Major clean refactoring, variable path length, error codes, several bugfixes.
|
|
|
|
# Joris Dedieu <joris@pontiac3.nfrance.com> # Portability framework, FreeBSD support, bugfixes.
|
|
|
|
# Ludovic Rousseau <ludovic.rousseau@gmail.com> # Lot of bugfixes.
|
|
|
|
# Yann 'Ze' Richard <ze@nbox.org> # Do not fail on missing commands.
|
|
|
|
# François Schmidts <fschmidts@olfeo.com> # Simpler SSH_IP acquiring method.
|
|
|
|
# Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use.
|
|
|
|
# Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir.
|
2012-08-11 18:46:05 -04:00
|
|
|
# Luc Didry <luc@fiat-tux.fr> # Zsh port
|
2012-08-14 09:59:36 -04:00
|
|
|
# Olivier Mengué <dolmen@cpan.org> # Major optimizations on host parsing
|
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
|
|
|
|
2012-08-14 08:12:33 -04:00
|
|
|
_LP_WORKING_SHELL=bash
|
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"
|
2012-08-14 06:08:43 -04:00
|
|
|
elif test -n "$ZSH_VERSION" ; then
|
2012-08-14 08:12:33 -04:00
|
|
|
_LP_WORKING_SHELL=zsh
|
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"
|
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-07-22 16:28:50 -04:00
|
|
|
# Colors declarations
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$LP_OS" == "FreeBSD" ]] ; then
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-08-13 18:56:27 -04:00
|
|
|
BOLD="${_LP_OPEN_ESC}$(tput md)${_LP_CLOSE_ESC}"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-08-14 04:56:34 -04:00
|
|
|
BLACK="${_LP_OPEN_ESC}$(tput AF 0)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_GRAY="${_LP_OPEN_ESC}$(tput md ; tput AF 0)${_LP_CLOSE_ESC}"
|
|
|
|
WHITE="${_LP_OPEN_ESC}$(tput AF 7)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_WHITE="${_LP_OPEN_ESC}$(tput md ; tput AF 7)${_LP_CLOSE_ESC}"
|
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
RED="${_LP_OPEN_ESC}$(tput AF 1)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_RED="${_LP_OPEN_ESC}$(tput md ; tput AF 1)${_LP_CLOSE_ESC}"
|
|
|
|
WARN_RED="${_LP_OPEN_ESC}$(tput AF 0 ; tput setab 1)${_LP_CLOSE_ESC}"
|
|
|
|
CRIT_RED="${_LP_OPEN_ESC}$(tput md; tput AF 7 ; tput setab 1)${_LP_CLOSE_ESC}"
|
2012-08-14 09:06:58 -04:00
|
|
|
DANGER_RED="${_LP_OPEN_ESC}$(tput md; tput AF 3 ; tput setab 1)${_LP_CLOSE_ESC}"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
GREEN="${_LP_OPEN_ESC}$(tput AF 2)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_GREEN="${_LP_OPEN_ESC}$(tput md ; tput AF 2)${_LP_CLOSE_ESC}"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
YELLOW="${_LP_OPEN_ESC}$(tput AF 3)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_YELLOW="${_LP_OPEN_ESC}$(tput md ; tput AF 3)${_LP_CLOSE_ESC}"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
BLUE="${_LP_OPEN_ESC}$(tput AF 4)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_BLUE="${_LP_OPEN_ESC}$(tput md ; tput AF 4)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
PURPLE="${_LP_OPEN_ESC}$(tput AF 5)${_LP_CLOSE_ESC}"
|
|
|
|
PINK="${_LP_OPEN_ESC}$(tput md ; tput AF 5)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
CYAN="${_LP_OPEN_ESC}$(tput AF 6)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_CYAN="${_LP_OPEN_ESC}$(tput md ; tput AF 6)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
NO_COL="${_LP_OPEN_ESC}$(tput me)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
else
|
2012-08-21 17:39:46 -04:00
|
|
|
# default for Linux, SunOS and Darwin
|
2012-08-13 18:56:27 -04:00
|
|
|
BOLD="${_LP_OPEN_ESC}$(tput bold)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-14 04:56:34 -04:00
|
|
|
BLACK="${_LP_OPEN_ESC}$(tput setaf 0)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_GRAY="${_LP_OPEN_ESC}$(tput bold ; tput setaf 0)${_LP_CLOSE_ESC}"
|
|
|
|
WHITE="${_LP_OPEN_ESC}$(tput setaf 7)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_WHITE="${_LP_OPEN_ESC}$(tput bold ; tput setaf 7)${_LP_CLOSE_ESC}"
|
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
RED="${_LP_OPEN_ESC}$(tput setaf 1)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_RED="${_LP_OPEN_ESC}$(tput bold ; tput setaf 1)${_LP_CLOSE_ESC}"
|
|
|
|
WARN_RED="${_LP_OPEN_ESC}$(tput setaf 0 ; tput setab 1)${_LP_CLOSE_ESC}"
|
|
|
|
CRIT_RED="${_LP_OPEN_ESC}$(tput bold; tput setaf 7 ; tput setab 1)${_LP_CLOSE_ESC}"
|
2012-08-14 09:06:58 -04:00
|
|
|
DANGER_RED="${_LP_OPEN_ESC}$(tput bold; tput setaf 3 ; tput setab 1)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
GREEN="${_LP_OPEN_ESC}$(tput setaf 2)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_GREEN="${_LP_OPEN_ESC}$(tput bold ; tput setaf 2)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
YELLOW="${_LP_OPEN_ESC}$(tput setaf 3)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_YELLOW="${_LP_OPEN_ESC}$(tput bold ; tput setaf 3)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
BLUE="${_LP_OPEN_ESC}$(tput setaf 4)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_BLUE="${_LP_OPEN_ESC}$(tput bold ; tput setaf 4)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
PURPLE="${_LP_OPEN_ESC}$(tput setaf 5)${_LP_CLOSE_ESC}"
|
|
|
|
PINK="${_LP_OPEN_ESC}$(tput bold ; tput setaf 5)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
CYAN="${_LP_OPEN_ESC}$(tput setaf 6)${_LP_CLOSE_ESC}"
|
|
|
|
BOLD_CYAN="${_LP_OPEN_ESC}$(tput bold ; tput setaf 6)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
2012-08-13 18:37:36 -04:00
|
|
|
NO_COL="${_LP_OPEN_ESC}$(tput sgr0)${_LP_CLOSE_ESC}"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
fi
|
2012-07-17 03:22:40 -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:35:14 -04:00
|
|
|
FreeBSD|Darwin)
|
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"
|
|
|
|
}
|
|
|
|
;;
|
|
|
|
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 #
|
|
|
|
#################
|
|
|
|
|
|
|
|
# Note: configuration is called _after_ colors declarations, because of themes.
|
|
|
|
|
|
|
|
# Default values
|
|
|
|
LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
|
|
|
|
LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60}
|
|
|
|
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
|
|
|
|
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
|
|
|
|
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
|
|
|
|
LP_PS1=${LP_PS1:-""}
|
2012-08-17 03:52:28 -04:00
|
|
|
LP_SVN_STATUS_OPTS=${LP_SVN_STATUS_OPTS:---depth=immediates}
|
2012-08-16 09:34:03 -04:00
|
|
|
|
2012-08-16 09:16:48 -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}
|
|
|
|
LP_ENABLE_JOBS=${LP_ENABLE_JOBS:-1}
|
|
|
|
LP_ENABLE_LOAD=${LP_ENABLE_LOAD:-1}
|
|
|
|
LP_ENABLE_BATT=${LP_ENABLE_BATT:-1}
|
2012-08-15 05:10:17 -04:00
|
|
|
LP_ENABLE_GIT=${LP_ENABLE_GIT:-1}
|
|
|
|
LP_ENABLE_SVN=${LP_ENABLE_SVN:-1}
|
2012-08-16 04:40:20 -04:00
|
|
|
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
|
2012-08-17 10:31:45 -04:00
|
|
|
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
|
2012-08-14 05:10:12 -04:00
|
|
|
|
2012-08-16 09:22:01 -04:00
|
|
|
LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"}
|
|
|
|
LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"}
|
|
|
|
LP_MARK_LOAD=${LP_MARK_LOAD:-"⌂"}
|
|
|
|
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-08-16 09:51:01 -04:00
|
|
|
LP_MARK_UNTRACKED=${LP_MARK_UNTRACKED:-"*"}
|
2012-08-16 06:13:40 -04:00
|
|
|
|
2012-08-21 11:03:35 -04:00
|
|
|
LP_COLOR_PATH=${LP_COLOR_PATH:-$BOLD}
|
2012-08-14 06:09:11 -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}
|
2012-08-21 07:58:35 -04:00
|
|
|
LP_COLOR_MARK=${LP_COLOR_MARK:-$BOLD}
|
2012-08-14 06:09:11 -04:00
|
|
|
LP_COLOR_MARK_ROOT=${LP_COLOR_MARK_ROOT:-$BOLD_RED}
|
2012-08-14 09:06:58 -04:00
|
|
|
LP_COLOR_USER_LOGGED=${LP_COLOR_USER_LOGGED:-""}
|
2012-08-14 06:09:11 -04:00
|
|
|
LP_COLOR_USER_ALT=${LP_COLOR_USER_ALT:-$BOLD}
|
|
|
|
LP_COLOR_USER_ROOT=${_ROOT:-$BOLD_YELLOW}
|
2012-08-14 09:06:58 -04:00
|
|
|
LP_COLOR_HOST=${LP_COLOR_HOST:-""}
|
2012-08-14 06:09:11 -04:00
|
|
|
LP_COLOR_SSH=${LP_COLOR_SSH:-$BOLD_CYAN}
|
|
|
|
LP_COLOR_TELNET=${LP_COLOR_TELNET:-$WARN_RED}
|
|
|
|
LP_COLOR_WRITE=${LP_COLOR_WRITE:-$GREEN}
|
|
|
|
LP_COLOR_NOWRITE=${LP_COLOR_NOWRITE:-$RED}
|
2012-08-14 08:35:20 -04:00
|
|
|
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}
|
2012-08-17 10:31:45 -04:00
|
|
|
LP_COLOR_TIME=${LP_COLOR_TIME:-$BLUE}
|
2012-08-14 05:10:12 -04:00
|
|
|
|
2012-08-14 09:06:58 -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 05:10:12 -04:00
|
|
|
# Default config file may be the XDG standard ~/.config/liquidpromptrc,
|
|
|
|
# but heirloom dotfile has priority.
|
|
|
|
_lp_source_config()
|
|
|
|
{
|
|
|
|
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-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 ; }
|
|
|
|
[[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; }
|
|
|
|
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
|
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.
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_user()
|
2012-07-19 09:08:18 -04:00
|
|
|
{
|
2012-08-13 17:15:24 -04:00
|
|
|
local user
|
2012-07-19 09:08:18 -04:00
|
|
|
# if user is not root
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$EUID" -ne "0" ]] ; then
|
2012-07-19 09:08:18 -04:00
|
|
|
# if user is not login user
|
2012-07-20 06:54:12 -04:00
|
|
|
if [[ ${USER} != "$(logname 2>/dev/null)" ]]; then
|
2012-08-14 06:01:14 -04:00
|
|
|
user="${LP_COLOR_USER_ALT}${_LP_USER_SYMBOL}${NO_COL}"
|
2012-07-19 09:08:18 -04:00
|
|
|
else
|
2012-08-14 06:01:14 -04:00
|
|
|
user="${LP_COLOR_USER_LOGGED}${_LP_USER_SYMBOL}${NO_COL}"
|
2012-07-19 09:08:18 -04:00
|
|
|
fi
|
|
|
|
else
|
2012-08-14 06:01:14 -04:00
|
|
|
user="${LP_COLOR_USER_ROOT}${_LP_USER_SYMBOL}${NO_COL}"
|
2012-07-19 09:08:18 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo -ne $user
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-08-14 09:11:48 -04:00
|
|
|
if [[ -n "$SSH_CLIENT$SSH2_CLIENT" ]] ; then
|
|
|
|
echo ssh
|
2012-07-17 03:50:30 -04:00
|
|
|
else
|
2012-08-14 09:11:48 -04:00
|
|
|
# TODO check on *BSD
|
|
|
|
local sess_src=$(who am i | sed -n 's/.*(\(.*\))/\1/p')
|
2012-08-14 09:55:23 -04:00
|
|
|
if [[ -z "$sess_src" || "$sess_src" = :0.0 || "$sess_src" == :0 ]] ; then
|
2012-08-14 09:11:48 -04:00
|
|
|
echo lcl # Local
|
|
|
|
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
|
|
|
|
case "$(_lp_connection)" in
|
|
|
|
lcl)
|
2012-08-16 10:31:00 -04:00
|
|
|
if [[ "$LP_HOSTNAME_ALWAYS" != 1 ]] ; then
|
2012-08-14 09:11:48 -04:00
|
|
|
LP_HOST="${NO_COL}" # no hostname if local
|
2012-07-17 03:50:30 -04:00
|
|
|
else
|
2012-08-14 09:11:48 -04:00
|
|
|
LP_HOST="${NO_COL}@${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)
|
|
|
|
LP_HOST="${NO_COL}@${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}"
|
2012-08-14 09:11:48 -04:00
|
|
|
;;
|
2012-08-14 05:43:58 -04:00
|
|
|
tel)
|
|
|
|
LP_HOST="${NO_COL}@${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
LP_HOST="${NO_COL}@${_LP_HOST_SYMBOL}" # defaults to no color
|
|
|
|
;;
|
|
|
|
esac
|
2012-07-17 03:50:30 -04:00
|
|
|
|
2012-08-14 05:43:58 -04:00
|
|
|
# Useless now, so undefine
|
|
|
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_PROXY" != 1 ]] && return
|
|
|
|
|
2012-08-09 06:11:51 -04:00
|
|
|
if [[ ! -z "$http_proxy" ]] ; then
|
2012-08-16 14:54:16 -04:00
|
|
|
echo -ne $LP_MARK_PROXY
|
2012-08-09 06:11:51 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-08-21 16:17:37 -04:00
|
|
|
local p=$(echo "$1" | sed -e "s|$HOME|~|")
|
2012-08-16 12:35:07 -04:00
|
|
|
if [[ "$LP_ENABLE_SHORTEN_PATH" != 1 ]] ; then
|
2012-08-21 16:17:37 -04:00
|
|
|
echo "$p"
|
2012-08-16 09:16:48 -04:00
|
|
|
return
|
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
# the character that will replace the part of the path that is masked
|
|
|
|
local mask=" … "
|
2012-08-11 18:46:05 -04:00
|
|
|
# index of the directory to keep from the root (starts at 0 whith bash, 1 with zsh)
|
2012-07-31 16:15:07 -04:00
|
|
|
local keep=$((LP_PATH_KEEP-1))
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
2012-08-11 18:46:05 -04:00
|
|
|
keep=$LP_PATH_KEEP
|
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
|
|
|
|
local len_percent=$2
|
|
|
|
|
|
|
|
local len="${#p}"
|
2012-08-03 15:29:59 -04:00
|
|
|
|
2012-08-07 14:59:58 -04:00
|
|
|
local max_len=$((${COLUMNS:-80}*$len_percent/100))
|
2012-07-29 16:19:06 -04:00
|
|
|
local mask_len="${#mask}"
|
2012-08-07 15:16:51 -04:00
|
|
|
local slashes=0
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-12 04:08:59 -04:00
|
|
|
if [[ "$len" -gt "$max_len" ]]
|
|
|
|
then
|
|
|
|
# finds all the '/' in
|
|
|
|
# the path and stores their
|
|
|
|
# positions
|
|
|
|
#
|
2012-08-11 18:46:05 -04:00
|
|
|
local pos=()
|
|
|
|
for ((i=0;i<len;i++))
|
|
|
|
do
|
|
|
|
if [[ "${p:i:1}" == "/" ]]
|
|
|
|
then
|
|
|
|
pos=(${pos[@]} $i)
|
|
|
|
slashes=$((${slashes}+1))
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
pos=(${pos[@]} $len)
|
|
|
|
|
|
|
|
# we have the '/'s, let's find the
|
|
|
|
# left-most that doesn't break the
|
|
|
|
# length limit
|
|
|
|
#
|
|
|
|
local i=$keep
|
|
|
|
if [[ $keep > $slashes ]] ; then
|
|
|
|
i=$slashes
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
2012-08-11 18:46:05 -04:00
|
|
|
while [[ "$((len-pos[i]))" -gt "$((max_len-mask_len))" ]]
|
|
|
|
do
|
|
|
|
i=$((i+1))
|
|
|
|
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
|
|
|
#
|
2012-08-11 18:46:05 -04:00
|
|
|
if [[ "${pos[i]}" -eq "0" ]]
|
|
|
|
then
|
|
|
|
# the path is shorter than
|
|
|
|
# the maximum allowed length,
|
|
|
|
# so no need for ...
|
|
|
|
#
|
|
|
|
echo "$p"
|
2012-07-29 16:19:06 -04:00
|
|
|
|
2012-08-11 18:46:05 -04:00
|
|
|
elif [[ "${pos[i]}" = "$len" ]]
|
|
|
|
then
|
|
|
|
# constraints are broken because
|
|
|
|
# the maximum allowed size is smaller
|
|
|
|
# than the last part of the path, plus
|
|
|
|
# ' … '
|
|
|
|
#
|
|
|
|
echo "${p:0:((${pos[${keep}]}+1))}${mask}${p:((len-max_len+mask_len))}"
|
|
|
|
else
|
|
|
|
# constraints are satisfied, at least
|
|
|
|
# some parts of the path, plus ' … ', are
|
|
|
|
# shorter than the maximum allowed size
|
|
|
|
#
|
|
|
|
echo "${p:0:((${pos[${keep}]}+1))}${mask}${p:pos[i]}"
|
|
|
|
fi
|
2012-08-12 04:08:59 -04:00
|
|
|
else
|
|
|
|
echo "$p"
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
2012-08-12 04:51:29 -04:00
|
|
|
if [[ "$len" -gt "$max_len" ]]; then
|
|
|
|
echo "%-${keep}~%${max_len}<${mask}<%~%<<"
|
|
|
|
else
|
|
|
|
echo "%~"
|
|
|
|
fi
|
2012-07-29 16:19:06 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
# Either attached running jobs (started with $ myjob &)
|
|
|
|
# or attached stopped jobs (suspended with Ctrl-Z)
|
2012-07-29 16:05:19 -04:00
|
|
|
# or detached screens sessions running on the host
|
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) ))
|
2012-07-30 05:01:04 -04:00
|
|
|
local screens=$(screen -ls 2> /dev/null | grep -c Detach )
|
2012-08-10 08:28:18 -04:00
|
|
|
local m_detached="d"
|
|
|
|
local m_stop="z"
|
|
|
|
local m_run="&"
|
2012-08-13 17:15:24 -04:00
|
|
|
local rep
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-08-10 09:08:08 -04:00
|
|
|
# d/&/z
|
|
|
|
if [[ $screens != "0" && $running != "0" && $stopped != "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-08-10 09:08:08 -04:00
|
|
|
# _/&/_
|
|
|
|
elif [[ $screens == "0" && $running != "0" && $stopped == "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-08-10 09:08:08 -04:00
|
|
|
# _/_/z
|
|
|
|
elif [[ $screens == "0" && $running == "0" && $stopped != "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-08-10 09:08:08 -04:00
|
|
|
# d/_/_
|
|
|
|
elif [[ $screens != "0" && $running == "0" && $stopped == "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-08-10 09:08:08 -04:00
|
|
|
# d/&/_
|
|
|
|
elif [[ $screens != "0" && $running != "0" && $stopped == "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-08-10 09:08:08 -04:00
|
|
|
# d/_/z
|
|
|
|
elif [[ $screens != "0" && $running == "0" && $stopped != "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
|
2012-08-10 09:08:08 -04:00
|
|
|
|
|
|
|
# _/&/z
|
|
|
|
elif [[ $screens == "0" && $running != "0" && $stopped != "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
rep="${NO_COL}${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
echo -ne "$rep"
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2012-07-19 05:21:18 -04:00
|
|
|
# Display the return value of the last command, if different from zero
|
2012-08-13 17:15:24 -04:00
|
|
|
_lp_return_value()
|
2012-07-19 05:21:18 -04:00
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$1" -ne "0" ]]
|
2012-07-19 05:21:18 -04:00
|
|
|
then
|
|
|
|
echo -ne "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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
|
|
|
######################
|
|
|
|
|
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
|
|
|
|
|
2012-08-20 08:36:12 -04:00
|
|
|
topdir="$(git rev-parse --git-dir 2>/dev/null)"
|
|
|
|
if [[ -n "$topdir" ]] && [[ "$(basename $topdir)" == '.git' ]] && [[ ! -z "$(git branch)" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
echo -n "$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p;')"
|
|
|
|
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
|
|
|
|
branch=$(_lp_git_branch)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$branch" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local GD
|
2012-07-17 03:23:44 -04:00
|
|
|
git diff --quiet >/dev/null 2>&1
|
|
|
|
GD=$?
|
2012-08-13 17:15:24 -04:00
|
|
|
|
|
|
|
local GDC
|
2012-07-17 03:23:44 -04:00
|
|
|
git diff --cached --quiet >/dev/null 2>&1
|
|
|
|
GDC=$?
|
|
|
|
|
2012-08-16 08:08:07 -04:00
|
|
|
local has_untracked
|
|
|
|
has_untracked=$(git status 2>/dev/null | grep '\(# Untracked\)')
|
|
|
|
if [[ -z "$has_untracked" ]] ; then
|
|
|
|
has_untracked=""
|
|
|
|
else
|
2012-08-16 09:51:01 -04:00
|
|
|
has_untracked="$LP_MARK_UNTRACKED"
|
2012-08-16 08:08:07 -04:00
|
|
|
fi
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local has_commit
|
2012-07-17 03:23:44 -04:00
|
|
|
has_commit=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ -z "$has_commit" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
has_commit=0
|
2012-07-19 04:49:07 -04:00
|
|
|
fi
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$GD" -eq 1 || "$GDC" -eq "1" ]] ; then
|
2012-08-13 17:15:24 -04:00
|
|
|
local has_line
|
2012-08-20 08:36:12 -04:00
|
|
|
has_lines=$(git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
|
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
|
2012-08-16 08:28:55 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})${LP_COLOR_CHANGES}${has_untracked}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-08-16 08:28:55 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${LP_COLOR_CHANGES}${has_untracked}${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
|
2012-08-16 08:28:55 -04:00
|
|
|
ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})${LP_COLOR_COMMITS}${has_untracked}${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-08-16 08:08:07 -04:00
|
|
|
ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}" # nothing to commit or push
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
fi
|
2012-08-10 08:40:50 -04:00
|
|
|
echo -ne "$ret"
|
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)"
|
2012-08-17 11:52:49 -04:00
|
|
|
[[ $? -eq 0 ]] && echo "$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
|
|
|
{
|
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
|
|
|
|
branch=$(_lp_hg_branch)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$branch" ]] ; then
|
2012-08-13 14:40:36 -04:00
|
|
|
if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then
|
2012-08-14 08:35:20 -04:00
|
|
|
ret="${LP_COLOR_UP}${branch}${NO_COL}"
|
2012-07-19 03:59:09 -04:00
|
|
|
else
|
2012-08-14 08:35:20 -04:00
|
|
|
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}" # changes to commit
|
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' )
|
|
|
|
# Make url relative to root
|
|
|
|
url="${url:${#root}}"
|
|
|
|
if [[ "$url" == */trunk* ]] ; then
|
|
|
|
echo trunk
|
|
|
|
else
|
|
|
|
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
|
2012-08-17 03:52:28 -04:00
|
|
|
commits=$(( $(svn status $LP_SVN_STATUS_OPTIONS | grep -c -v "?") ))
|
|
|
|
if [[ $commits -eq 0 ]] ; then
|
|
|
|
echo "${LP_COLOR_UP}${branch}${NO_COL}"
|
2012-07-19 04:49:07 -04:00
|
|
|
else
|
2012-08-17 03:52:28 -04:00
|
|
|
echo "${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_COMMITS}$commits${NO_COL})" # changes to commit
|
2012-07-19 04:49:07 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_BATT" != 1 ]] && return
|
2012-08-13 17:15:24 -04:00
|
|
|
local acpi
|
|
|
|
acpi="$(acpi --battery 2>/dev/null)"
|
|
|
|
local bat
|
|
|
|
bat=$( echo $acpi | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/")
|
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
|
2012-08-13 17:15:24 -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-13 17:15:24 -04:00
|
|
|
local ret
|
2012-08-14 08:35:20 -04:00
|
|
|
ret="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}"
|
2012-08-14 09:06:58 -04:00
|
|
|
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}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-08-14 09:06:58 -04:00
|
|
|
# for debugging purpose
|
|
|
|
ret="${ret}${LP_COLORMAP_0}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-12 04:38:52 -04:00
|
|
|
echo -ne "${ret}${bat}%${NO_COL}"
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
2012-08-12 04:38:52 -04:00
|
|
|
echo -ne "${ret}${bat}%%${NO_COL}"
|
|
|
|
fi
|
2012-08-12 04:52:03 -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.
|
|
|
|
|
2012-08-16 12:35:07 -04:00
|
|
|
[[ "$LP_ENABLE_LOAD" != 1 ]] && return
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local load
|
2012-08-14 18:11:34 -04:00
|
|
|
load="$(_lp_cpu_load | sed 's/\.//g;s/^0*//g' )"
|
|
|
|
let "load=${load:-0}/$_lp_CPUNUM"
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-07-31 16:15:07 -04:00
|
|
|
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
|
2012-07-17 03:23:44 -04:00
|
|
|
then
|
2012-08-13 17:15:24 -04:00
|
|
|
local ret
|
2012-08-16 09:22:01 -04:00
|
|
|
ret="${LP_MARK_LOAD}${NO_COL}"
|
2012-08-14 09:06:58 -04:00
|
|
|
if [[ $load -ge 0 ]] && [[ $load -lt 20 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_0}"
|
|
|
|
elif [[ $load -ge 20 ]] && [[ $load -lt 40 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_1}"
|
|
|
|
elif [[ $load -ge 40 ]] && [[ $load -lt 60 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_2}"
|
|
|
|
elif [[ $load -ge 60 ]] && [[ $load -lt 80 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_3}"
|
|
|
|
elif [[ $load -ge 80 ]] && [[ $load -lt 100 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_4}"
|
|
|
|
elif [[ $load -ge 100 ]] && [[ $load -lt 120 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_5}"
|
|
|
|
elif [[ $load -ge 120 ]] && [[ $load -lt 140 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_6}"
|
|
|
|
elif [[ $load -ge 140 ]] && [[ $load -lt 160 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_7}"
|
|
|
|
elif [[ $load -ge 160 ]] && [[ $load -lt 180 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_8}"
|
|
|
|
elif [[ $load -ge 180 ]] ; then
|
|
|
|
ret="${ret}${LP_COLORMAP_9}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-08-14 09:06:58 -04:00
|
|
|
ret="${ret}${LP_COLORMAP_0}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-13 09:20:20 -04:00
|
|
|
ret="${ret}$load%${NO_COL}"
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
2012-08-13 09:20:20 -04:00
|
|
|
ret="${ret}$load%%${NO_COL}"
|
|
|
|
fi
|
2012-07-17 03:23:44 -04:00
|
|
|
echo -ne "${ret}"
|
|
|
|
fi
|
2012-07-07 03:32:29 -04:00
|
|
|
}
|
|
|
|
|
2012-07-19 05:21:18 -04:00
|
|
|
|
|
|
|
##########
|
|
|
|
# DESIGN #
|
|
|
|
##########
|
|
|
|
|
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 COL
|
2012-08-14 06:01:14 -04:00
|
|
|
COL=${LP_COLOR_MARK}
|
2012-08-10 08:40:50 -04:00
|
|
|
if [[ "$EUID" -eq "0" ]] ; then
|
2012-08-14 06:01:14 -04:00
|
|
|
COL=${LP_COLOR_MARK_ROOT}
|
2012-08-10 08:40:50 -04:00
|
|
|
fi
|
|
|
|
|
2012-08-13 17:15:24 -04:00
|
|
|
local mark
|
2012-08-16 07:07:32 -04:00
|
|
|
mark="\\\$"
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
2012-08-16 08:11:52 -04:00
|
|
|
mark="%(!.#.%%)"
|
2012-08-11 18:46:05 -04:00
|
|
|
fi
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ ! -z $(_lp_git_branch) ]] ; then
|
2012-08-16 11:56:36 -04:00
|
|
|
mark=$LP_MARK_GIT
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ ! -z $(_lp_hg_branch) ]] ; then
|
2012-08-16 11:56:36 -04:00
|
|
|
mark=$LP_MARK_HG
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ ! -z $(_lp_svn_branch) ]] ; then
|
2012-08-16 11:56:36 -04:00
|
|
|
mark=$LP_MARK_SVN
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-08-10 08:40:50 -04:00
|
|
|
echo -ne "${COL}${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
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$1" ]] ; then
|
2012-07-19 05:27:22 -04:00
|
|
|
echo -n "$1 "
|
2012-07-19 05:14:42 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$1" ]] ; then
|
2012-07-19 05:27:22 -04:00
|
|
|
echo -n " $1"
|
2012-07-19 05:14:42 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$1" ]] ; then
|
2012-07-19 05:27:22 -04:00
|
|
|
echo -n " $1 "
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-08-17 09:47:44 -04:00
|
|
|
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
|
|
|
|
2012-08-17 09:47:44 -04:00
|
|
|
###################
|
|
|
|
# CURRENT TIME #
|
|
|
|
###################
|
|
|
|
_lp_time()
|
|
|
|
{
|
|
|
|
[[ "$LP_ENABLE_TIME" != 1 ]] && return
|
2012-08-17 10:31:45 -04:00
|
|
|
echo -ne "${LP_COLOR_TIME}$(date +%H:%M:%S)${NO_COL}"
|
2012-08-17 09:47:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-19 05:21:18 -04:00
|
|
|
|
|
|
|
########################
|
|
|
|
# Construct the prompt #
|
|
|
|
########################
|
|
|
|
|
2012-08-16 14:18:29 -04:00
|
|
|
_lp_set_prompt()
|
2012-07-17 03:22:40 -04:00
|
|
|
{
|
2012-07-19 05:27:22 -04:00
|
|
|
# as this get the last returned code, it should be called first
|
2012-08-16 06:13:40 -04:00
|
|
|
LP_ERR="${LP_COLOR_ERR}$(_lp_sl $(_lp_return_value $?))${NO_COL}"
|
2012-07-19 05:27:22 -04:00
|
|
|
|
2012-08-05 05:19:19 -04:00
|
|
|
# execute the old prompt
|
|
|
|
$LP_OLD_PROMPT_COMMAND
|
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# left of main prompt: space at right
|
2012-08-13 17:15:24 -04:00
|
|
|
LP_JOBS=$(_lp_sr "$(_lp_jobcount_color)")
|
|
|
|
LP_LOAD=$(_lp_sr "$(_lp_load_color)")
|
|
|
|
LP_BATT=$(_lp_sr "$(_lp_battery_color)")
|
2012-08-17 10:31:45 -04:00
|
|
|
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
|
2012-08-13 17:15:24 -04:00
|
|
|
LP_USER=$(_lp_user)
|
2012-08-14 05:43:58 -04:00
|
|
|
# LP_HOST is a global set at load time
|
2012-08-13 17:15:24 -04:00
|
|
|
LP_PERM=$(_lp_permissions_color)
|
|
|
|
LP_PWD=$(_lp_shorten_path "$PWD" $LP_PATH_LENGTH)
|
2012-08-16 06:13:40 -04:00
|
|
|
LP_PROXY="${LP_COLOR_PROXY}$(_lp_proxy)${NO_COL}"
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# right of main prompt: space at left
|
2012-08-13 17:15:24 -04:00
|
|
|
LP_GIT=$(_lp_sl "$(_lp_git_branch_color)")
|
|
|
|
LP_HG=$(_lp_sl "$(_lp_hg_branch_color)")
|
|
|
|
LP_SVN=$(_lp_sl "$(_lp_svn_branch_color)")
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# end of the prompt line: double spaces
|
2012-08-13 17:15:24 -04:00
|
|
|
LP_MARK=$(_lp_sb "$(_lp_smart_mark)")
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-08-16 06:13:40 -04:00
|
|
|
# Different path color if root
|
|
|
|
if [[ "$EUID" -ne "0" ]] ; then
|
|
|
|
LP_PWD="${LP_COLOR_PATH}${LP_PWD}${NO_COL}"
|
|
|
|
else
|
|
|
|
LP_PWD="${LP_COLOR_PATH_ROOT}${LP_PWD}${NO_COL}"
|
|
|
|
fi
|
|
|
|
|
2012-08-10 09:46:44 -04:00
|
|
|
if [[ -z $LP_PS1 ]] ; then
|
2012-08-17 09:47:44 -04:00
|
|
|
# add time, jobs, load and battery
|
|
|
|
PS1="${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"
|
2012-08-10 09:46:44 -04:00
|
|
|
# add user, host and permissions colon
|
2012-08-14 05:10:12 -04:00
|
|
|
PS1="${PS1}[${LP_USER}${LP_HOST}${LP_PERM}"
|
2012-07-19 08:17:32 -04:00
|
|
|
|
2012-08-10 09:46:44 -04:00
|
|
|
# if not root
|
|
|
|
if [[ "$EUID" -ne "0" ]]
|
|
|
|
then
|
|
|
|
# path in foreground color
|
2012-08-16 06:13:40 -04:00
|
|
|
PS1="${PS1}${LP_PWD}]${LP_PROXY}"
|
2012-08-10 09:46:44 -04:00
|
|
|
# add VCS infos
|
2012-08-13 17:15:24 -04:00
|
|
|
PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}"
|
2012-08-10 09:46:44 -04:00
|
|
|
else
|
|
|
|
# path in yellow
|
2012-08-16 06:13:40 -04:00
|
|
|
PS1="${PS1}${LP_PWD}]${LP_PROXY}"
|
2012-08-10 09:46:44 -04:00
|
|
|
# do not add VCS infos
|
|
|
|
fi
|
|
|
|
# add return code and prompt mark
|
2012-08-16 06:13:40 -04:00
|
|
|
PS1="${PS1}${LP_ERR}${LP_MARK}"
|
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
|
|
|
}
|
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"
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-11 18:46:05 -04:00
|
|
|
LP_OLD_PROMPT_COMMAND="$PROMPT_COMMAND"
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
2012-08-11 18:46:05 -04:00
|
|
|
LP_OLD_PROMPT_COMMAND="$precmd"
|
|
|
|
fi
|
|
|
|
fi
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-16 14:18:29 -04:00
|
|
|
PROMPT_COMMAND=_lp_set_prompt
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
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
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-11 18:46:05 -04:00
|
|
|
PROMPT_COMMAND=$LP_OLD_PROMPT_COMMAND
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
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="\$ "
|
2012-08-13 17:15:24 -04:00
|
|
|
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
|
2012-08-11 18:46:05 -04:00
|
|
|
PROMPT_COMMAND=$LP_OLD_PROMPT_COMMAND
|
2012-08-13 17:15:24 -04:00
|
|
|
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
|
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:
|