Merge pull request #1 from nojhan/master

Sync with official repo
This commit is contained in:
Julien Pecqueur 2013-03-28 02:54:14 -07:00
commit 5e232b7b73
4 changed files with 277 additions and 161 deletions

View File

@ -26,9 +26,9 @@ in a git repository on a server, at branch "myb":
`1r [user@server:~/liquidprompt] myb ± `
A liquid prompt displaying everything may look like this:
A liquid prompt displaying everything (a rare event!) may look like this:
`⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3)* 125 ± `
`code ⌁24% ⌂42% 3d/2&/1z [user@server:~/ … /code/liquidprompt]↥ master(+10/-5,3)*+ 125 ± `
It displays:
@ -39,18 +39,18 @@ a red ⌁ if the battery is discharging but above threshold;
threshold, with a colormap, going more and more red with decreasing power;
* the average of the processors load, if it is over a given limit, with a
colormap that became more and more noticeable with increasing load;
* the number of detached sessions (`screen`), if there is any;
* the number of detached sessions (`screen` or `tmux`), if there are any;
* the number of attached sleeping jobs (when you interrupt a command with Ctrl-Z
and bring it back with `fg`), if there is any;
* the number of attached running jobs (commands started with a `&`), if there is
and bring it back with `fg`), if there are any;
* the number of attached running jobs (commands started with a `&`), if there are
any;
* a pair of square brackets, in blue if your current shell is running in a
terminal multiplexer (screen or tmux);
terminal multiplexer (`screen` or `tmux`);
* the current user, in bold yellow if it is root, in light white if it is not
the same as the login user;
* a blue @ if the connection has X11 support;
* the current host, if you are connected via an SSH or telnet connection, with
different colors for each case;
* a green @ if the connection has X11 support, a yellow one if not;
* the current host, if you are connected via a telnet connection (in bold red)
or SSH (either a blue hostname or differents colors for different hosts);
* a green colon if the user has write permissions on the current directory,
a red one if he has not;
* the current directory in bold, shortened if it takes too much space, while
@ -58,7 +58,7 @@ preserving the first two directories;
* the current Python virtual environment, if any;
* an up arrow if an HTTP proxy is in use;
* the name of the current branch if you are in a version control repository
(git, mercurial, subversion or fossil), in green if everything is up
(git, mercurial, subversion, bazaar or fossil), in green if everything is up
to date, in red if there is changes, in yellow if there is pending
commits to push;
* the number of added/deleted lines (git) or files (fossil), if
@ -98,8 +98,8 @@ Apart from obvious ones, some features depends on specific commands. If you do
not install them, the corresponding feature will not be available, but you will
see no error.
* battery status need `acpi`,
* detached sessions is looking for `screen`.
* battery status needs `acpi`.
* detached sessions is looking for `screen` and/or `tmux`.
* VCS support features needs… `git`, `hg` or `svn`, but you knew it.
For other features, the script uses commands that should be available on a large
@ -126,7 +126,7 @@ it only when he is different from the logged one
You can also force some features to be disabled, to save some time in the prompt
building:
* `LP_ENABLE_PERM`, if you want to detect if the directory is writable
* `LP_ENABLE_SHORTEN_PATH`, if you to shorten the path display
* `LP_ENABLE_SHORTEN_PATH`, if you want to shorten the path display
* `LP_ENABLE_PROXY`, if you want to detect if a proxy is used
* `LP_ENABLE_JOBS`, if you want to have jobs informations
* `LP_ENABLE_LOAD`, if you want to have load informations
@ -134,10 +134,12 @@ building:
* `LP_ENABLE_GIT`, if you want to have git informations
* `LP_ENABLE_SVN`, if you want to have subversion informations
* `LP_ENABLE_HG`, if you want to have mercurial informations
* `LP_ENABLE_BZR`, if you want to have bazaar informations
* `LP_ENABLE_FOSSIL`, if you want to have fossil informations
* `LP_ENABLE_VCS_ROOT`, if you want to show VCS informations with root account
* `LP_ENABLE_TITLE`, if you want to use the prompt as your terminal window's title
* `LP_ENABLE_SCREEN_TITLE`, if you want to use the prompt as your screen window's title
* `LP_ENABLE_SSH_COLORS`, if you want different colors for hosts you SSH in
Note that if required commands are not installed, enabling the
corresponding feature will have no effect.
@ -173,13 +175,17 @@ a keyword to your different terminals:
You can sort what you want to see by sourcing your favorite template file
(`*.ps1`) in the configuration file.
You can start from the `liquid.ps1` file, which show the default settings.
To use your own configuration, just set `LP_PS1_FILE` to your own file path in
your `~/.liquipromptrc` and you're done.
Those scripts basically export the `LP_PS1` variable, by appending features and
theme colors.
Available features:
* `LP_BATT` battery
* `LP_LOAD` load
* `LP_JOBS` screen sessions/running jobs/suspended jobs
* `LP_JOBS` detached screen or tmux sessions/running jobs/suspended jobs
* `LP_USER` user
* `LP_HOST` hostname
* `LP_PERM` a colon ":"
@ -224,7 +230,7 @@ Set to a null string "" if you do not want color.
* Color of the proxy mark
* `LP_COLOR_PROXY`
* Jobs count
* `LP_COLOR_JOB_D` Detached (aka screen sessions)
* `LP_COLOR_JOB_D` Detached (screen/tmux sessions without attached clients)
* `LP_COLOR_JOB_R` Running (xterm &)
* `LP_COLOR_JOB_Z` Sleeping (Ctrl-Z)
* `LP_COLOR_IN_MULTIPLEXER` currently running in a terminal multiplexer
@ -243,7 +249,7 @@ Set to a null string "" if you do not want color.
* `LP_COLOR_TELNET` connected via telnet
* `LP_COLOR_X11_ON` connected with X11 support
* `LP_COLOR_X11_OFF` connected without X11 support
* Separation mark (aka permiison in the working dir)
* Separation mark (by default, the colon before the path)
* `LP_COLOR_WRITE` have write permission
* `LP_COLOR_NOWRITE` do not have write permission
* VCS
@ -269,6 +275,7 @@ Special characters:
* `LP_MARK_SVN` (default: "‡") prompt mark in svn repositories
* `LP_MARK_GIT` (default: "±") prompt mark in git repositories
* `LP_MARK_FOSSIL` (default: "⌘") prompt mark in fossil repositories
* `LP_MARK_BZR` (default: "⚯") prompt mark in bazaar repositories
* `LP_MARK_UNTRACKED` (default: "*") if git has untracked files
* `LP_MARK_STASH` (default: "+") if git has stashed modifications
* `LP_MARK_BRACKET_OPEN` (default: "[") marks around the main part of the prompt
@ -284,7 +291,6 @@ Special characters:
Liquid prompt is distributed under the GNU Affero General Public License
version 3.
* detached sessions only looks for `screen`, a `tmux` support would be nice…
* Does not display the number of commits to be pushed in Mercurial repositories.
* Browsing into very large subversion repositories may dramatically slow down
the display of the liquid prompt.

View File

@ -20,6 +20,7 @@ if [[ "$(locale -k LC_CTYPE | sed -n 's/^charmap="\(.*\)"/\1/p')" == *"UTF-8"* ]
LP_MARK_FOSSIL="⌘" # prompt mark in fossil repositories
LP_MARK_UNTRACKED="*" # if git has untracked files
LP_MARK_STASH="+" # if git has stashs
LP_MARK_SHORTEN_PATH="…" # prompt mark in shortened paths
else
# If charset is anything else, fallback to ASCII chars
LP_MARK_BATTERY="b"
@ -32,6 +33,7 @@ else
LP_MARK_FOSSIL="f"
LP_MARK_UNTRACKED="*"
LP_MARK_STASH="+"
LP_MARK_SHORTEN_PATH="..."
fi
# Do not prefix the prompt

View File

@ -24,18 +24,25 @@
# AUTHORS #
###########
# nojhan <nojhan@gmail.com> # Main author.
# Alex Prengère <alex.prengere@amadeus.com> # untracked git files
# 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 <francois.schmidts@gmail.com> # small code fix, _lp_get_dirtrim
# Thomas Debesse <thomas.debesse@gmail.com> # Fix columns use.
# Clément Mathieu <clement@unportant.info> # Bazaar support
# David Loureiro <david.loureiro@sysfera.com> # small portability fix
# Étienne Deparis <etienne.deparis@umaneti.net> # Fossil support
# Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir.
# Luc Didry <luc@fiat-tux.fr> # Zsh port
# François Schmidts <francois.schmidts@gmail.com> # small code fix, _lp_get_dirtrim
# 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.
# Olivier Mengué <dolmen@cpan.org> # Major optimizations on host parsing
# Frédéric Lepied # Python virtual env
# Clément MATHIEU # Bazaar support
# 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.
# See the README.md file for a summary of features.
@ -193,6 +200,7 @@ _lp_source_config()
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
LP_USER_ALWAYS=${LP_USER_ALWAYS:-1}
LP_PERCENTS_ALWAYS=${LP_PERCENTS_ALWAYS:-1}
LP_PS1=${LP_PS1:-""}
LP_PS1_PREFIX=${LP_PS1_PREFIX:-""}
LP_TITLE_OPEN=${LP_TITLE_OPEN:-"\e]0;"}
@ -216,6 +224,7 @@ _lp_source_config()
LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0}
LP_ENABLE_SCREEN_TITLE=${LP_ENABLE_SCREEN_TITLE:-0}
LP_ENABLE_SSH_COLORS=${LP_ENABLE_SSH_COLORS:-0}
LP_DISABLED_VCS_PATH=${LP_DISABLED_VCS_PATH:-""}
LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"}
@ -231,6 +240,7 @@ _lp_source_config()
LP_MARK_STASH=${LP_MARK_STASH:-"+"}
LP_MARK_BRACKET_OPEN=${LP_MARK_BRACKET_OPEN:-"["}
LP_MARK_BRACKET_CLOSE=${LP_MARK_BRACKET_CLOSE:-"]"}
LP_MARK_SHORTEN_PATH=${LP_MARK_SHORTEN_PATH:-" … "}
LP_COLOR_PATH=${LP_COLOR_PATH:-$BOLD_WHITE}
LP_COLOR_PATH_ROOT=${LP_COLOR_PATH_ROOT:-$BOLD_YELLOW}
@ -246,6 +256,7 @@ _lp_source_config()
LP_COLOR_USER_ROOT=${_ROOT:-$BOLD_YELLOW}
LP_COLOR_HOST=${LP_COLOR_HOST:-""}
LP_COLOR_SSH=${LP_COLOR_SSH:-$BLUE}
LP_COLOR_SU=${LP_COLOR_SU:-$BOLD_YELLOW}
LP_COLOR_TELNET=${LP_COLOR_TELNET:-$WARN_RED}
LP_COLOR_X11_ON=${LP_COLOR_X11:-$GREEN}
LP_COLOR_X11_OFF=${LP_COLOR_X11:-$YELLOW}
@ -308,6 +319,13 @@ unset _lp_source_config
[[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; }
[[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; }
# Escape the given strings
# Must be used for all strings that may comes from remote sources,
# like VCS branch names
_lp_escape()
{
printf "%q" "$*"
}
###############
@ -337,13 +355,16 @@ fi
_lp_connection()
{
if [[ -n "$SSH_CLIENT$SSH2_CLIENT" ]] ; then
if [[ -n "$SSH_CLIENT$SSH2_CLIENT$SSH_TTY" ]] ; then
echo ssh
else
# TODO check on *BSD
local sess_src=$(who am i | sed -n 's/.*(\(.*\))/\1/p')
local sess_parent=$(ps -o comm= -p $PPID)
if [[ -z "$sess_src" || "$sess_src" = ":"* ]] ; then
echo lcl # Local
elif [[ "$sess_parent" = "su" || "$sess_parent" = "sudo" ]] ; then
echo su # Remote su/sudo
else
echo tel # Telnet
fi
@ -384,7 +405,23 @@ lcl)
fi
;;
ssh)
# If we want a different color for each host
if [[ "$LP_ENABLE_SSH_COLORS" -eq "1" ]]; then
# 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
;;
su)
LP_HOST="${LP_HOST}${LP_COLOR_SU}${_LP_HOST_SYMBOL}${NO_COL}"
;;
tel)
LP_HOST="${LP_HOST}${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}"
@ -431,7 +468,7 @@ _lp_shorten_path()
return
fi
# the character that will replace the part of the path that is masked
local mask=""
local mask="$LP_MARK_SHORTEN_PATH"
# index of the directory to keep from the root (starts at 0 whith bash, 1 with zsh)
local keep=$((LP_PATH_KEEP-1))
if [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
@ -567,50 +604,39 @@ _lp_virtualenv()
# Related jobs #
################
# Either attached running jobs (started with $ myjob &)
# or attached stopped jobs (suspended with Ctrl-Z)
# or detached screens sessions running on the host
# 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)
_lp_jobcount_color()
{
[[ "$LP_ENABLE_JOBS" != 1 ]] && return
local running=$(( $(jobs -r | wc -l) ))
local stopped=$(( $(jobs -s | wc -l) ))
local screens=$(screen -ls 2> /dev/null | grep -c Detach ) # FIXME add tmux support
local n_screen=$(screen -ls 2> /dev/null | grep -c Detach)
local n_tmux=$(tmux list-sessions 2> /dev/null | grep -cv attached)
local detached=$(( $n_screen + $n_tmux ))
local m_detached="d"
local m_stop="z"
local m_run="&"
local rep
local ret=""
# d/&/z
if [[ $screens != "0" && $running != "0" && $stopped != "0" ]] ; then
rep="${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}"
# _/&/_
elif [[ $screens == "0" && $running != "0" && $stopped == "0" ]] ; then
rep="${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}"
# _/_/z
elif [[ $screens == "0" && $running == "0" && $stopped != "0" ]] ; then
rep="${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
# d/_/_
elif [[ $screens != "0" && $running == "0" && $stopped == "0" ]] ; then
rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}"
# d/&/_
elif [[ $screens != "0" && $running != "0" && $stopped == "0" ]] ; then
rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}"
# d/_/z
elif [[ $screens != "0" && $running == "0" && $stopped != "0" ]] ; then
rep="${LP_COLOR_JOB_D}${screens}${m_detached}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
# _/&/z
elif [[ $screens == "0" && $running != "0" && $stopped != "0" ]] ; then
rep="${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}/${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
if [[ $detached != "0" ]] ; then
ret="${ret}${LP_COLOR_JOB_D}${detached}${m_detached}${NO_COL}"
fi
echo -ne "$rep"
if [[ $running != "0" ]] ; then
if [[ $ret != "" ]] ; then ret="${ret}/"; fi
ret="${ret}${LP_COLOR_JOB_R}${running}${m_run}${NO_COL}"
fi
if [[ $stopped != "0" ]] ; then
if [[ $ret != "" ]] ; then ret="${ret}/"; fi
ret="${ret}${LP_COLOR_JOB_Z}${stopped}${m_stop}${NO_COL}"
fi
echo -ne "$ret"
}
@ -659,11 +685,15 @@ _lp_git_branch()
[[ "$LP_ENABLE_GIT" != 1 ]] && return
local gitdir
gitdir="$(git rev-parse --git-dir 2>/dev/null)"
[[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return
local branch
branch="$(git symbolic-ref HEAD 2>/dev/null)"
[[ $? -ne 0 || ! $gitdir =~ (.*\/)?\.git.* ]] && return
local branch="$(git symbolic-ref HEAD 2>/dev/null)"
if [[ $? -ne 0 || -z "$branch" ]] ; then
# In detached head state, use commit instead
branch="$(git rev-parse --short HEAD 2>/dev/null)"
fi
[[ $? -ne 0 || -z "$branch" ]] && return
echo "${branch#refs/heads/}"
branch="${branch#refs/heads/}"
echo $(_lp_escape "$branch")
}
# Set a color depending on the branch state:
@ -704,11 +734,27 @@ _lp_git_branch_color()
has_stash="$LP_COLOR_COMMITS$LP_MARK_STASH"
fi
local remote
remote="$(git config --get branch.${branch}.remote 2>/dev/null)"
# if git has no upstream, use origin
if [[ -z "$remote" ]]; then
remote="origin"
fi
local remote_branch
remote_branch="$(git config --get branch.${branch}.merge 2>/dev/null)"
# without any remote branch, use the same name
if [[ -z "$remote_branch" ]]; then
remote_branch="$branch"
fi
local has_commit
has_commit=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null)
has_commit=0
if [[ -n "$remote" && -n "$remote_branch" ]] ; then
has_commit=$(git rev-list --no-merges --count $remote/${remote_branch}..${branch} 2>/dev/null)
if [[ -z "$has_commit" ]] ; then
has_commit=0
fi
fi
if [[ "$GD" -eq 1 || "$GDC" -eq "1" ]] ; then
local has_line
has_lines=$(git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}')
@ -739,7 +785,8 @@ _lp_hg_branch()
[[ "$LP_ENABLE_HG" != 1 ]] && return
local branch
branch="$(hg branch 2>/dev/null)"
[[ $? -eq 0 ]] && echo "$branch"
[[ $? -eq 0 ]] && echo $(_lp_escape "$branch")
}
# Set a color depending on the branch state:
@ -754,10 +801,37 @@ _lp_hg_branch_color()
local ret
branch=$(_lp_hg_branch)
if [[ ! -z "$branch" ]] ; then
if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then
ret="${LP_COLOR_UP}${branch}${NO_COL}"
local has_untracked
has_untracked=$(hg status 2>/dev/null | grep '\(^\?\)' | wc -l)
if [[ -z "$has_untracked" ]] ; then
has_untracked=""
else
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}" # changes to commit
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
if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then
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
else
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
ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit
fi
fi
echo -ne "$ret"
fi
@ -774,13 +848,16 @@ _lp_svn_branch()
local url
local result
eval $(LANG=C LC_ALL=C svn info 2>/dev/null | sed -n 's/^URL: \(.*\)/url="\1"/p;s/^Repository Root: \(.*\)/root="\1"/p' )
if [[ "$root" == "" ]]; then
return
fi
# Make url relative to root
url="${url:${#root}}"
if [[ "$url" == */trunk* ]] ; then
echo trunk
echo -n trunk
else
result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root")
echo $result
echo -n $result # FIXME should be: echo -n $(_lp_escape "${result}")
fi
}
@ -818,7 +895,7 @@ _lp_fossil_branch()
local branch
branch=$(fossil status 2>/dev/null | grep tags: | cut -c17-)
if [[ -n "$branch" ]] ; then
echo "$branch"
echo $(_lp_escape "$branch")
else
if fossil info &>/dev/null ; then
echo "no-tag"
@ -887,7 +964,7 @@ _lp_fossil_branch_color()
branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}"
fi
fi
echo -ne "$branch"
echo $(_lp_escape "$branch")
fi
}
@ -897,10 +974,10 @@ _lp_fossil_branch_color()
_lp_bzr_branch()
{
[[ "$LP_ENABLE_BZR" != 1 ]] && return
local output
output=$(bzr nick 2> /dev/null)
local branch
branch=$(bzr nick 2> /dev/null)
[[ $? -ne 0 ]] && return
echo "$output"
echo $(_lp_escape "$branch")
}
@ -1020,8 +1097,9 @@ _lp_battery_color()
# discharging and under threshold
elif [[ "$bat" != "" ]] ; then
local ret
ret="${LP_COLOR_DISCHARGING_UNDER}${mark}${NO_COL}"
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
@ -1046,11 +1124,13 @@ _lp_battery_color()
fi
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
echo -ne "${ret}${bat}%${NO_COL}"
ret="${ret}${bat}%"
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
echo -ne "${ret}${bat}%%${NO_COL}"
fi
ret="${ret}${bat}%%"
fi
fi # LP_PERCENTS_ALWAYS
echo -ne "${ret}${NO_COL}"
fi # ret
}
@ -1077,7 +1157,7 @@ _lp_load_color()
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
then
local ret
ret="${LP_MARK_LOAD}"
ret=""
if [[ $load -ge 0 ]] && [[ $load -lt 20 ]] ; then
ret="${ret}${LP_COLORMAP_0}"
elif [[ $load -ge 20 ]] && [[ $load -lt 40 ]] ; then
@ -1101,12 +1181,16 @@ _lp_load_color()
else
ret="${ret}${LP_COLORMAP_0}"
fi
ret="$ret${LP_MARK_LOAD}"
if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
ret="${ret}$load%${NO_COL}"
ret="${ret}$load%"
elif [[ "$_LP_WORKING_SHELL" == "zsh" ]]; then
ret="${ret}$load%%${NO_COL}"
ret="${ret}$load%%"
fi
echo -ne "${ret}"
fi
echo -ne "${ret}${NO_COL}"
fi
}
@ -1146,6 +1230,9 @@ _lp_title()
[[ "$LP_ENABLE_SCREEN_TITLE" != "1" ]] && return
local title="${LP_SCREEN_TITLE_OPEN}${txt}${LP_SCREEN_TITLE_CLOSE}"
;;
linux*)
local title=""
;;
*)
local title="${_LP_OPEN_ESC}${LP_TITLE_OPEN}${txt}${LP_TITLE_CLOSE}${_LP_CLOSE_ESC}"
;;
@ -1170,6 +1257,8 @@ _lp_smart_mark()
fi
if [[ "$1" == "git" ]]; then
mark=$LP_MARK_GIT
elif [[ "$1" == "git-svn" ]]; then
mark="$LP_MARK_GIT$LP_MARK_SVN"
elif [[ "$1" == "hg" ]]; then
mark=$LP_MARK_HG
elif [[ "$1" == "svn" ]]; then
@ -1261,6 +1350,12 @@ _lp_set_prompt()
if [[ "$(_lp_are_vcs_disabled)" -eq "0" ]] ; then
LP_VCS="$(_lp_git_branch_color)"
LP_VCS_TYPES="git"
if [[ -n "$LP_VCS" ]]; then
# If this is a git-svn repository
if [[ -d "$(git rev-parse --git-dir 2>/dev/null)/svn" ]]; then
LP_VCS_TYPES="git-svn"
fi
fi # git-svn
if [[ -z "$LP_VCS" ]]; then
LP_VCS="$(_lp_hg_branch_color)"
LP_VCS_TYPES="hg"
@ -1273,11 +1368,11 @@ _lp_set_prompt()
if [[ -z "$LP_VCS" ]]; then
LP_VCS="$(_lp_bzr_branch_color)"
LP_VCS_TYPES="bzr"
fi
fi
fi
fi
fi
fi # bzr
fi # fossil
fi # svn
fi # hg
fi # disabled
if [[ -z "$LP_VCS" ]] ; then
LP_VCS_TYPES=""
else
@ -1298,6 +1393,7 @@ _lp_set_prompt()
elif [[ -n "$LP_VCS_TYPES" ]]; then
case "$LP_VCS_TYPES" in
git) LP_VCS=$(_lp_sl "$(_lp_git_branch_color)");;
git-svn)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)");;
@ -1305,6 +1401,10 @@ _lp_set_prompt()
esac
fi
if [[ -f "$LP_PS1_FILE" ]]; then
source "$LP_PS1_FILE"
fi
if [[ -z $LP_PS1 ]] ; then
# add title escape time, jobs, load and battery
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"

View File

@ -6,7 +6,7 @@
# If you want to use different themes and features,
# you can load the corresponding files here:
#source ~/code/liquidprompt/nojhan.theme
#source ~/code/liquidprompt/nojhan.ps1
#LP_PS1_FILE="~/code/liquidprompt/nojhan.ps1"
#############
# BEHAVIOUR #
@ -38,6 +38,11 @@ LP_HOSTNAME_ALWAYS=0
# set to 0 if you want to hide the logged user (it will always display different users)
LP_USER_ALWAYS=1
# Do you want to display the percentages of load/batteries along with their
# corresponding marks? Set to 0 to only print the colored marks.
# Defaults to 1 (display percentages)
LP_PERCENTS_ALWAYS=1
# Do you want to use the permissions feature ?
# Recommended value is 1
LP_ENABLE_PERM=1
@ -100,6 +105,9 @@ LP_ENABLE_TITLE=0
# Enable Title for screen and byobu
LP_ENABLE_SCREEN_TITLE=0
# Use differents colors for differents hosts you SSH in
LP_ENABLE_SSH_COLORS=0
# Specify a list of complete and colon (":") separated paths in which, all vcs
# will be disabled
LP_DISABLED_VCS_PATH=""