2012-07-07 03:32:29 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-07-17 03:22:40 -04:00
|
|
|
# An intelligent and non intrusive prompt for bash
|
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 (c) nojhan <nojhan@gmail.com>
|
2012-07-17 03:22:40 -04:00
|
|
|
# 2012 (c) Aurelien Requiem <aurelien@requiem.fr> #major rewrite and adaptation
|
2012-07-07 05:35:58 -04:00
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
# Below are function for having a flexible dynamic prompt for power user:
|
2012-07-17 03:22:40 -04:00
|
|
|
# - display the battery level (if necessary), with colormap (if any battery attached)
|
2012-07-26 05:22:17 -04:00
|
|
|
# - if necessary, prints a counter for jobs that are attached to the current
|
2012-07-29 16:05:19 -04:00
|
|
|
# term (e.g. xterm &) or that are sleeping (e.g. Ctrl-z) or detached "screen" sessions
|
2012-07-07 03:32:29 -04:00
|
|
|
# - display the load average, colored with a colormap
|
2012-07-17 03:22:40 -04:00
|
|
|
# - displays the colored login@hostname
|
|
|
|
# - when root displays in red
|
|
|
|
# - when user displays in green
|
|
|
|
# - displays the current path in blue
|
|
|
|
# - when user, print the colored git branch name (if in a git repository):
|
|
|
|
# red = some changes are not commited, and yellow in parenthesis any unpushed commits (if any)
|
|
|
|
# yellow = some commits are not pushed. Number of commits in parenthesis
|
|
|
|
# green = no changes or commits
|
|
|
|
|
|
|
|
# Check for recent enough version of bash.
|
2012-07-30 15:46:29 -04:00
|
|
|
[[ -z "$BASH_VERSION" || -z "$PS1" || -z "$TERM" ]] && return;
|
2012-07-17 03:22:40 -04:00
|
|
|
|
|
|
|
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $bmajor -lt 3 ]] || [[ $bmajor -eq 3 && $bminor -lt 2 ]]; then
|
2012-07-17 03:23:44 -04:00
|
|
|
unset bash bmajor bminor
|
|
|
|
return
|
2012-07-07 03:32:29 -04:00
|
|
|
fi
|
2012-07-17 03:22:40 -04:00
|
|
|
unset bash bmajor bminor
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-22 16:28:50 -04:00
|
|
|
|
2012-07-24 03:49:51 -04:00
|
|
|
#################
|
|
|
|
# CONFIGURATION #
|
|
|
|
#################
|
|
|
|
|
2012-08-03 17:07:32 -04:00
|
|
|
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_REVERSE=${LP_REVERSE:-0}
|
2012-07-24 03:49:51 -04:00
|
|
|
|
2012-07-31 16:15:07 -04:00
|
|
|
source ~/.liquidpromptrc 2> /dev/null
|
2012-07-30 18:07:50 -04:00
|
|
|
|
|
|
|
|
2012-07-22 16:28:50 -04:00
|
|
|
###############
|
|
|
|
# OS specific #
|
|
|
|
###############
|
|
|
|
|
|
|
|
# OS detection, default to Linux
|
|
|
|
OS="Linux"
|
2012-07-22 16:11:09 -04:00
|
|
|
case $(uname) in
|
2012-07-22 16:28:50 -04:00
|
|
|
"Linux" ) OS="Linux" ;;
|
2012-07-22 16:11:09 -04:00
|
|
|
"FreeBSD") OS="FreeBSD" ;;
|
2012-07-31 04:57:27 -04:00
|
|
|
"Darwin") OS="Darwin" ;;
|
2012-07-23 10:05:49 -04:00
|
|
|
"DragonFly") OS="FreeBSD" ;;
|
|
|
|
"SunOS") OS="SunOS" ;;
|
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-07-22 16:11:09 -04:00
|
|
|
if [[ "$OS" == "FreeBSD" ]] ; then
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-22 16:11:09 -04:00
|
|
|
BLACK="\[$(tput AF 0)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_GRAY="\[$(tput md ; tput AF 0)\]"
|
|
|
|
WHITE="\[$(tput AF 7)\]"
|
|
|
|
BOLD_WHITE="\[$(tput md ; tput AF 7)\]"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-07-22 16:11:09 -04:00
|
|
|
RED="\[$(tput AF 1)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_RED="\[$(tput md ; tput AF 1)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
WARN_RED="\[$(tput AF 0 ; tput setab 1)\]"
|
|
|
|
CRIT_RED="\[$(tput md; tput AF 7 ; tput setab 1)\]"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-07-22 16:11:09 -04:00
|
|
|
GREEN="\[$(tput AF 2)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_GREEN="\[$(tput md ; tput AF 2)\]"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-07-22 16:11:09 -04:00
|
|
|
YELLOW="\[$(tput AF 3)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_YELLOW="\[$(tput md ; tput AF 3)\]"
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-07-22 16:11:09 -04:00
|
|
|
BLUE="\[$(tput AF 4)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_BLUE="\[$(tput md ; tput AF 4)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
PURPLE="\[$(tput AF 5)\]"
|
|
|
|
PINK="\[$(tput md ; tput AF 5)\]"
|
|
|
|
|
|
|
|
CYAN="\[$(tput AF 6)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_CYAN="\[$(tput md ; tput AF 6)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
NO_COL="\[$(tput me)\]"
|
|
|
|
|
|
|
|
else
|
|
|
|
# default to Linux
|
|
|
|
BLACK="\[$(tput setaf 0)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_GRAY="\[$(tput bold ; tput setaf 0)\]"
|
|
|
|
WHITE="\[$(tput setaf 7)\]"
|
|
|
|
BOLD_WHITE="\[$(tput bold ; tput setaf 7)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
RED="\[$(tput setaf 1)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_RED="\[$(tput bold ; tput setaf 1)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
WARN_RED="\[$(tput setaf 0 ; tput setab 1)\]"
|
|
|
|
CRIT_RED="\[$(tput bold; tput setaf 7 ; tput setab 1)\]"
|
|
|
|
|
|
|
|
GREEN="\[$(tput setaf 2)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_GREEN="\[$(tput bold ; tput setaf 2)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
YELLOW="\[$(tput setaf 3)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_YELLOW="\[$(tput bold ; tput setaf 3)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
BLUE="\[$(tput setaf 4)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_BLUE="\[$(tput bold ; tput setaf 4)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
PURPLE="\[$(tput setaf 5)\]"
|
|
|
|
PINK="\[$(tput bold ; tput setaf 5)\]"
|
|
|
|
|
|
|
|
CYAN="\[$(tput setaf 6)\]"
|
2012-07-30 18:07:50 -04:00
|
|
|
BOLD_CYAN="\[$(tput bold ; tput setaf 6)\]"
|
2012-07-22 16:11:09 -04:00
|
|
|
|
|
|
|
NO_COL="\[$(tput sgr0)\]"
|
|
|
|
|
|
|
|
fi
|
2012-07-17 03:22:40 -04:00
|
|
|
|
2012-07-30 18:07:50 -04:00
|
|
|
# Foreground colors
|
|
|
|
# can be set to white or black
|
|
|
|
FG=$WHITE
|
|
|
|
BOLD_FG=$BOLD_WHITE
|
2012-07-31 16:15:07 -04:00
|
|
|
if [[ $LP_REVERSE == 1 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
FG=$BLACK
|
|
|
|
BOLD_FG=$BOLD_GRAY
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2012-07-20 06:50:05 -04:00
|
|
|
# get cpu number
|
2012-07-23 10:40:43 -04:00
|
|
|
__cpunum_Linux()
|
2012-07-20 06:50:05 -04:00
|
|
|
{
|
2012-07-26 05:24:29 -04:00
|
|
|
grep ^[Pp]rocessor /proc/cpuinfo | wc -l
|
2012-07-20 06:50:05 -04:00
|
|
|
}
|
|
|
|
|
2012-07-23 10:40:43 -04:00
|
|
|
__cpunum_FreeBSD()
|
2012-07-20 06:50:05 -04:00
|
|
|
{
|
2012-07-22 16:11:09 -04:00
|
|
|
sysctl -n hw.ncpu
|
2012-07-20 06:50:05 -04:00
|
|
|
}
|
|
|
|
|
2012-07-31 04:57:27 -04:00
|
|
|
__cpunum_Darwin()
|
|
|
|
{
|
2012-07-31 15:27:53 -04:00
|
|
|
__cpunum_FreeBSD
|
2012-07-31 04:57:27 -04:00
|
|
|
}
|
|
|
|
|
2012-07-23 10:40:43 -04:00
|
|
|
__cpunum_SunOS()
|
2012-07-23 10:05:49 -04:00
|
|
|
{
|
|
|
|
kstat -m cpu_info | grep "module: cpu_info" | wc -l
|
|
|
|
}
|
|
|
|
|
2012-07-20 06:50:05 -04:00
|
|
|
__CPUNUM=$(__cpunum_$OS)
|
|
|
|
|
|
|
|
|
|
|
|
# get current load
|
|
|
|
|
|
|
|
__load_Linux()
|
|
|
|
{
|
|
|
|
load=$(awk '{print $1}' /proc/loadavg)
|
|
|
|
echo -n "$load"
|
|
|
|
}
|
|
|
|
|
|
|
|
__load_FreeBSD()
|
|
|
|
{
|
|
|
|
load=$(LANG=C sysctl -n vm.loadavg | awk '{print $2}')
|
|
|
|
echo -n "$load"
|
|
|
|
}
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-31 04:57:27 -04:00
|
|
|
__load_Darwin()
|
|
|
|
{
|
2012-07-31 15:27:53 -04:00
|
|
|
__load_FreeBSD
|
2012-07-31 04:57:27 -04:00
|
|
|
}
|
|
|
|
|
2012-07-23 10:05:49 -04:00
|
|
|
__load_SunOS()
|
|
|
|
{
|
|
|
|
load=$(LANG=C uptime | awk '{print $10}'| sed -e 's/,//')
|
|
|
|
echo -n "$load"
|
|
|
|
}
|
|
|
|
|
2012-07-17 03:50:30 -04:00
|
|
|
|
2012-07-19 09:08:18 -04:00
|
|
|
###############
|
|
|
|
# Who are we? #
|
|
|
|
###############
|
|
|
|
|
|
|
|
# Yellow for root, light grey if the user is not the login one, else no color.
|
|
|
|
__user()
|
|
|
|
{
|
|
|
|
# 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-07-30 18:07:50 -04:00
|
|
|
user="${FG}\u${NO_COL}"
|
2012-07-19 09:08:18 -04:00
|
|
|
else
|
|
|
|
user="\u"
|
|
|
|
fi
|
|
|
|
else
|
2012-07-30 18:07:50 -04:00
|
|
|
user="${BOLD_YELLOW}\u${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? #
|
|
|
|
#################
|
|
|
|
|
|
|
|
__connection()
|
|
|
|
{
|
2012-07-30 16:05:20 -04:00
|
|
|
THIS_TTY=tty$(ps aux | grep $$ | grep bash | awk '{ print $7 }')
|
|
|
|
SESS_SRC=$(who | grep $THIS_TTY | awk '{ print $6 }')
|
2012-07-17 03:50:30 -04:00
|
|
|
|
|
|
|
# Are we in an SSH connexion?
|
|
|
|
SSH_FLAG=0
|
2012-07-17 05:01:54 -04:00
|
|
|
SSH_IP=${SSH_CLIENT%% *}
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $SSH_IP ]] ; then
|
2012-07-17 03:50:30 -04:00
|
|
|
SSH_FLAG=1
|
|
|
|
fi
|
2012-07-30 16:05:20 -04:00
|
|
|
SSH2_IP=$(echo $SSH2_CLIENT | awk '{ print $1 }')
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $SSH2_IP ]] ; then
|
2012-07-17 03:50:30 -04:00
|
|
|
SSH_FLAG=1
|
|
|
|
fi
|
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $SSH_FLAG -eq 1 ]] ; then
|
2012-07-17 03:50:30 -04:00
|
|
|
CONN="ssh"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ -z $SESS_SRC ]] ; then
|
2012-07-17 03:50:30 -04:00
|
|
|
CONN="lcl"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $SESS_SRC = "(:0.0)" || $SESS_SRC = "" ]] ; then
|
2012-07-17 03:50:30 -04:00
|
|
|
CONN="lcl"
|
|
|
|
else
|
|
|
|
CONN="tel"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -ne $CONN
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
__host_color()
|
|
|
|
{
|
|
|
|
conn=$(__connection)
|
|
|
|
|
|
|
|
ret="${NO_COL}"
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$conn" == "lcl" ]] ; then
|
2012-07-17 03:50:30 -04:00
|
|
|
ret="${ret}" # no hostname if local
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ "$conn" == "ssh" ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}@${BOLD_CYAN}\h"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ "$conn" == "tel" ]] ; then
|
2012-07-17 05:02:30 -04:00
|
|
|
ret="${ret}@${WARN_RED}\h"
|
2012-07-17 03:50:30 -04:00
|
|
|
else
|
2012-07-17 05:02:30 -04:00
|
|
|
ret="${ret}@\h"
|
2012-07-17 03:50:30 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo -ne "${ret}${NO_COL}"
|
|
|
|
}
|
|
|
|
|
2012-07-29 16:19:06 -04:00
|
|
|
# BASH function that shortens
|
|
|
|
# a very long path for display by removing
|
|
|
|
# the left most parts and replacing them
|
|
|
|
# with a leading ...
|
|
|
|
#
|
|
|
|
# the first argument is the path
|
|
|
|
#
|
|
|
|
# the second argument is the maximum allowed
|
|
|
|
# length including the '/'s and ...
|
|
|
|
# http://hbfs.wordpress.com/2009/09/01/short-pwd-in-bash-prompts/
|
|
|
|
#
|
|
|
|
# + keep some left part of the path if asked
|
|
|
|
__shorten_path()
|
|
|
|
{
|
|
|
|
# the character that will replace the part of the path that is masked
|
|
|
|
local mask=" … "
|
|
|
|
# index of the directory to keep from the root (starts at 0)
|
2012-07-31 16:15:07 -04:00
|
|
|
local keep=$((LP_PATH_KEEP-1))
|
2012-07-29 16:19:06 -04:00
|
|
|
|
|
|
|
local len_percent=$2
|
|
|
|
|
|
|
|
local p=$(echo "$1" | sed -e "s|$HOME|~|")
|
|
|
|
local len="${#p}"
|
2012-08-03 15:29:59 -04:00
|
|
|
|
|
|
|
if [ -z "$COLUMNS" ]
|
|
|
|
then
|
|
|
|
local columns=80
|
|
|
|
else
|
|
|
|
local columns=$COLUMNS
|
|
|
|
fi
|
|
|
|
local max_len=$(($columns*$len_percent/100))
|
2012-07-29 16:19:06 -04:00
|
|
|
local mask_len="${#mask}"
|
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$len" -gt "$max_len" ]]
|
2012-07-29 16:19:06 -04:00
|
|
|
then
|
|
|
|
# finds all the '/' in
|
|
|
|
# the path and stores their
|
|
|
|
# positions
|
|
|
|
#
|
|
|
|
local pos=()
|
|
|
|
for ((i=0;i<len;i++))
|
|
|
|
do
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "${p:i:1}" == "/" ]]
|
2012-07-29 16:19:06 -04:00
|
|
|
then
|
|
|
|
pos=(${pos[@]} $i)
|
|
|
|
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
|
2012-07-30 15:46:29 -04:00
|
|
|
while [[ "$((len-pos[i]))" -gt "$((max_len-mask_len))" ]]
|
2012-07-29 16:19:06 -04:00
|
|
|
do
|
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
# let us check if it's OK to
|
|
|
|
# print the whole thing
|
|
|
|
#
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "${pos[i]}" -eq "0" ]]
|
2012-07-29 16:19:06 -04:00
|
|
|
then
|
|
|
|
# the path is shorter than
|
|
|
|
# the maximum allowed length,
|
|
|
|
# so no need for ...
|
|
|
|
#
|
|
|
|
echo "$p"
|
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ "${pos[i]}" = "$len" ]]
|
2012-07-29 16:19:06 -04:00
|
|
|
then
|
|
|
|
# constraints are broken because
|
|
|
|
# the maximum allowed size is smaller
|
|
|
|
# than the last part of the path, plus
|
|
|
|
# '…'
|
|
|
|
#
|
|
|
|
echo "${p:0:((${pos[${keep}]}+1))}${mask}${p:((len-max_len+mask_len))}"
|
|
|
|
else
|
|
|
|
# constraints are satisfied, at least
|
|
|
|
# some parts of the path, plus …, are
|
|
|
|
# shorter than the maximum allowed size
|
|
|
|
#
|
|
|
|
echo "${p:0:((${pos[${keep}]}+1))}${mask}${p:pos[i]}"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$p"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display a ":"
|
|
|
|
# colored in green if user have write permission on the current directory
|
|
|
|
# colored in red if it have not.
|
|
|
|
__permissions_color()
|
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ -w "${PWD}" ]]; then
|
2012-07-29 16:19:06 -04:00
|
|
|
echo "${GREEN}:${NO_COL}"
|
|
|
|
else
|
|
|
|
echo "${RED}:${NO_COL}"
|
|
|
|
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-07-17 03:22:40 -04:00
|
|
|
__jobcount_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2012-07-29 16:05:19 -04:00
|
|
|
local running=$(jobs -r | wc -l | tr -d " ")
|
|
|
|
local stopped=$(jobs -s | wc -l | tr -d " ")
|
2012-07-30 05:01:04 -04:00
|
|
|
local screens=$(screen -ls 2> /dev/null | grep -c Detach )
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $running != "0" && $stopped != "0" && $screens != "0" ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}/${YELLOW}${running}r${NO_COL}/${BOLD_YELLOW}${stopped}t${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $running != "0" && $stopped == "0" && $screens == "0" ]] ; then
|
2012-07-19 05:14:42 -04:00
|
|
|
rep="${NO_COL}${YELLOW}${running}r${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $running == "0" && $stopped != "0" && $screens == "0" ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
rep="${NO_COL}${BOLD_YELLOW}${stopped}t${NO_COL}"
|
2012-07-29 16:05:19 -04:00
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $running == "0" && $stopped == "0" && $screens != "0" ]] ; then
|
2012-07-29 16:05:19 -04:00
|
|
|
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}"
|
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $running != "0" && $stopped == "0" && $screens != "0" ]] ; then
|
2012-07-29 16:05:19 -04:00
|
|
|
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}/${YELLOW}${running}r${NO_COL}"
|
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $running == "0" && $stopped != "0" && $screens != "0" ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
rep="${NO_COL}${YELLOW}${screens}s${NO_COL}/${BOLD_YELLOW}${stopped}t${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
|
|
|
|
__return_value()
|
|
|
|
{
|
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-07-17 03:22:40 -04:00
|
|
|
__git_branch()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2012-07-30 16:05:20 -04:00
|
|
|
if git rev-parse --git-dir >/dev/null 2>&1 && [[ ! -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-07-17 03:22:40 -04:00
|
|
|
__git_branch_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2012-07-17 03:23:44 -04:00
|
|
|
command -v git >/dev/null 2>&1 || return 1;
|
|
|
|
branch=$(__git_branch)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$branch" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
|
|
|
|
git diff --quiet >/dev/null 2>&1
|
|
|
|
GD=$?
|
|
|
|
git diff --cached --quiet >/dev/null 2>&1
|
|
|
|
GDC=$?
|
|
|
|
|
|
|
|
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
|
|
|
|
if [[ "$has_commit" -gt "0" ]] ; then
|
2012-07-17 04:18:03 -04:00
|
|
|
# changes to commit and commits to push
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${RED}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${RED}${branch}${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-07-19 05:14:42 -04:00
|
|
|
ret="${YELLOW}${branch}${NO_COL}(${YELLOW}$has_commit${NO_COL})"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${GREEN}${branch}${NO_COL}" # nothing to commit or push
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo -ne "$ret"
|
|
|
|
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
|
|
|
|
__hg_branch()
|
|
|
|
{
|
|
|
|
branch="$(hg branch 2>/dev/null)"
|
2012-07-30 16:05:20 -04:00
|
|
|
if [[ $? -eq 0 ]] && [[ ! -z "$(hg branch)" ]] ; then
|
2012-07-19 03:59:09 -04:00
|
|
|
echo -n "$(hg branch)"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
__hg_branch_color()
|
|
|
|
{
|
|
|
|
command -v hg >/dev/null 2>&1 || return 1;
|
|
|
|
branch=$(__hg_branch)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$branch" ]] ; then
|
|
|
|
if [[ $(hg status --quiet -n | wc -l | sed -e "s/ //g") = 0 ]] ; then
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${GREEN}${branch}${NO_COL}"
|
2012-07-19 03:59:09 -04:00
|
|
|
else
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${RED}${branch}${NO_COL}" # changes to commit
|
2012-07-19 03:59:09 -04:00
|
|
|
fi
|
|
|
|
echo -ne "$ret"
|
|
|
|
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-07-19 04:49:07 -04:00
|
|
|
__svn_branch()
|
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ -d ".svn" ]] ; then
|
2012-07-19 04:49:07 -04:00
|
|
|
root=$(svn info --xml 2>/dev/null | grep "^<root>" | sed "s/^.*\/\([[:alpha:]]*\)<\/root>$/\1/")
|
2012-07-19 05:00:18 -04:00
|
|
|
branch=$(svn info --xml 2>/dev/null | grep "^<url>" | sed "s/.*\/$root\/\([[:alpha:]]*\).*<\/url>$/\1/")
|
2012-07-19 04:49:07 -04:00
|
|
|
if [[ "$branch" == "<url>"* ]] ; then
|
|
|
|
echo -n $root
|
|
|
|
else
|
|
|
|
echo -n $branch
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-07-19 05:00:18 -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
|
|
|
|
# Note that, due to subversion way of managing changes,
|
|
|
|
# informations are only displayed for the CURRENT directory.
|
2012-07-19 04:49:07 -04:00
|
|
|
__svn_branch_color()
|
|
|
|
{
|
|
|
|
command -v svn >/dev/null 2>&1 || return 1;
|
|
|
|
branch=$(__svn_branch)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z "$branch" ]] ; then
|
2012-07-19 04:49:07 -04:00
|
|
|
commits=$(svn status | grep -v "?" | wc -l)
|
2012-08-01 07:14:56 -04:00
|
|
|
commits=$((commits))
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $commits = 0 ]] ; then
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${GREEN}${branch}${NO_COL}"
|
2012-07-19 04:49:07 -04:00
|
|
|
else
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${RED}${branch}${NO_COL}(${YELLOW}$commits${NO_COL})" # changes to commit
|
2012-07-19 04:49:07 -04:00
|
|
|
fi
|
|
|
|
echo -ne "$ret"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-07 03:32:29 -04:00
|
|
|
##################
|
|
|
|
# Battery status #
|
|
|
|
##################
|
|
|
|
|
|
|
|
# Get the battery status in percent
|
2012-07-17 03:22:40 -04:00
|
|
|
# returns 1 if no battery support
|
|
|
|
__battery()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2012-07-17 03:23:44 -04:00
|
|
|
command -v acpi >/dev/null 2>&1 || return 1;
|
2012-07-30 16:05:20 -04:00
|
|
|
bat=$(acpi --battery 2>/dev/null | sed "s/^Battery .*, \([0-9]*\)%.*$/\1/")
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "${bat}" == "" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
return 1
|
|
|
|
fi
|
2012-07-31 16:15:07 -04:00
|
|
|
if [[ ${bat} -le $LP_BATTERY_THRESHOLD ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
echo -n "${bat}"
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
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
|
|
|
|
__battery_color()
|
2012-07-07 03:32:29 -04:00
|
|
|
{
|
2012-07-17 03:23:44 -04:00
|
|
|
bat=$(__battery)
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$?" = "1" ]] ; then return; fi; # no battery support
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$bat" != "" ]] ; then
|
2012-07-31 16:15:07 -04:00
|
|
|
if [[ ${bat} -gt $LP_BATTERY_THRESHOLD ]] ; then
|
2012-07-17 04:18:03 -04:00
|
|
|
return; # nothing displayed above 75%
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
|
2012-07-17 04:18:03 -04:00
|
|
|
ret="b${NO_COL}"
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ${bat} -le 75 ]] && [[ ${bat} -gt 50 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${BOLD_GREEN}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ ${bat} -le 40 ]] && [[ ${bat} -gt 20 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${BOLD_YELLOW}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ ${bat} -le 20 ]] && [[ ${bat} -gt 10 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${BOLD_RED}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ ${bat} -le 10 ]] && [[ ${bat} -gt 5 ]] ; then
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${ret}${WARN_RED}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${ret}${CRIT_RED}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
|
2012-07-17 04:18:03 -04:00
|
|
|
echo -ne "${ret}${bat}%${NO_COL}"
|
2012-07-17 03:23:44 -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-07-17 03:22:40 -04:00
|
|
|
__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-07-20 06:50:05 -04:00
|
|
|
loadval=$(__load_$OS)
|
2012-07-24 04:49:22 -04:00
|
|
|
load=$(echo $loadval | sed 's/\.//g;s/^0*//g' )
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ -z "$load" ]] ; then
|
2012-07-17 03:23:44 -04:00
|
|
|
load=0
|
|
|
|
fi
|
|
|
|
let "load=$load/$__CPUNUM"
|
|
|
|
|
2012-07-31 16:15:07 -04:00
|
|
|
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
|
2012-07-17 03:23:44 -04:00
|
|
|
then
|
2012-07-17 04:18:03 -04:00
|
|
|
ret="l${NO_COL}"
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ $load -lt 70 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${FG}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $load -ge 1 ]] && [[ $load -lt 80 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${BOLD_GREEN}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $load -ge 80 ]] && [[ $load -lt 95 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${BOLD_YELLOW}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $load -ge 95 ]] && [[ $load -lt 150 ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
ret="${ret}${BOLD_RED}"
|
2012-07-30 15:46:29 -04:00
|
|
|
elif [[ $load -ge 150 ]] && [[ $load -lt 200 ]] ; then
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${ret}${WARN_RED}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${ret}${CRIT_RED}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-07-19 05:14:42 -04:00
|
|
|
ret="${ret}$load%${NO_COL}"
|
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-07-19 03:59:09 -04:00
|
|
|
# Set the prompt mark to ± if VCS, # if root and else $
|
2012-07-17 03:50:30 -04:00
|
|
|
__smart_mark()
|
2012-07-17 03:22:40 -04:00
|
|
|
{
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$EUID" -ne "0" ]]
|
2012-07-17 03:23:44 -04:00
|
|
|
then
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z $(__git_branch) ]] || [[ ! -z $(__hg_branch) ]] || [[ ! -z $(__svn_branch) ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
echo -ne "${BOLD_FG}±${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-07-30 18:07:50 -04:00
|
|
|
echo -ne "${BOLD_FG}\\\$${NO_COL}"
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
|
|
|
else
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ ! -z $(__git_branch) ]] || [[ ! -z $(__hg_branch) ]] || [[ ! -z $(__svn_branch) ]] ; then
|
2012-07-30 18:07:50 -04:00
|
|
|
echo -ne "${BOLD_RED}±${NO_COL}"
|
2012-07-23 10:52:46 -04:00
|
|
|
else
|
2012-07-30 18:07:50 -04:00
|
|
|
echo -ne "${BOLD_RED}#${NO_COL}"
|
2012-07-23 10:52:46 -04:00
|
|
|
fi
|
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-07-19 08:17:32 -04:00
|
|
|
# insert a space on the right
|
2012-07-19 05:14:42 -04:00
|
|
|
__sr()
|
|
|
|
{
|
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-07-19 05:14:42 -04:00
|
|
|
__sl()
|
|
|
|
{
|
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-07-19 05:14:42 -04:00
|
|
|
__sb()
|
|
|
|
{
|
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-07-17 03:22:40 -04:00
|
|
|
}
|
|
|
|
|
2012-07-19 05:21:18 -04:00
|
|
|
|
|
|
|
########################
|
|
|
|
# Construct the prompt #
|
|
|
|
########################
|
|
|
|
|
2012-07-17 03:22:40 -04:00
|
|
|
__set_bash_prompt()
|
|
|
|
{
|
2012-07-19 05:27:22 -04:00
|
|
|
# as this get the last returned code, it should be called first
|
2012-07-30 16:05:20 -04:00
|
|
|
__RET=$(__sl "$(__return_value $?)")
|
2012-07-19 05:27:22 -04:00
|
|
|
|
|
|
|
# left of main prompt: space at right
|
2012-07-30 16:05:20 -04:00
|
|
|
__JOBS=$(__sr "$(__jobcount_color)")
|
|
|
|
__LOAD=$(__sr "$(__load_color)")
|
|
|
|
__BATT=$(__sr "$(__battery_color)")
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# in main prompt: no space
|
2012-07-30 16:05:20 -04:00
|
|
|
__USER=$(__user)
|
|
|
|
__HOST=$(__host_color)
|
|
|
|
__PERM=$(__permissions_color)
|
2012-07-31 16:15:07 -04:00
|
|
|
__PWD=$(__shorten_path $PWD $LP_PATH_LENGTH)
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# right of main prompt: space at left
|
2012-07-30 16:05:20 -04:00
|
|
|
__GIT=$(__sl "$(__git_branch_color)")
|
|
|
|
__HG=$(__sl "$(__hg_branch_color)")
|
|
|
|
__SVN=$(__sl "$(__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-07-30 16:05:20 -04:00
|
|
|
__MARK=$(__sb "$(__smart_mark)")
|
2012-07-19 05:14:42 -04:00
|
|
|
|
2012-07-24 20:42:42 -04:00
|
|
|
|
2012-07-19 08:17:32 -04:00
|
|
|
# add jobs, load and battery
|
2012-07-17 03:23:44 -04:00
|
|
|
PS1="${__BATT}${__LOAD}${__JOBS}"
|
2012-07-19 08:17:32 -04:00
|
|
|
|
|
|
|
# if not root
|
2012-07-30 15:46:29 -04:00
|
|
|
if [[ "$EUID" -ne "0" ]]
|
2012-07-17 03:23:44 -04:00
|
|
|
then
|
2012-07-30 18:07:50 -04:00
|
|
|
PS1="${PS1}[${__USER}${__HOST}${__PERM}${BOLD_FG}${__PWD}${NO_COL}]"
|
2012-07-19 04:49:07 -04:00
|
|
|
PS1="${PS1}${__GIT}${__HG}${__SVN}"
|
2012-07-17 03:23:44 -04:00
|
|
|
else
|
2012-07-29 16:19:06 -04:00
|
|
|
PS1="${PS1}[${__USER}${__HOST}${NO_COL}${__PERM}${YELLOW}${__PWD}${NO_COL}]"
|
2012-07-19 08:17:32 -04:00
|
|
|
# do not add VCS infos
|
2012-07-17 03:23:44 -04:00
|
|
|
fi
|
2012-07-19 05:17:40 -04:00
|
|
|
PS1="${PS1}${PURPLE}${__RET}${NO_COL}${__MARK}"
|
2012-07-17 03:23:44 -04:00
|
|
|
|
2012-07-19 05:27:22 -04:00
|
|
|
# Glue the bash prompt always go to the first column.
|
2012-07-17 03:23:44 -04:00
|
|
|
# Avoid glitches after interrupting a command with Ctrl-C
|
2012-07-26 03:50:20 -04:00
|
|
|
# Does not seem to be necessary anymore?
|
|
|
|
#PS1="\[\033[G\]${PS1}${NO_COL}"
|
2012-07-17 03:22:40 -04:00
|
|
|
}
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-17 03:22:40 -04:00
|
|
|
PROMPT_COMMAND=__set_bash_prompt
|
2012-07-07 03:32:29 -04:00
|
|
|
|
2012-07-25 08:19:53 -04:00
|
|
|
# vim: set ts=4 sw=4 tw=120 :
|