Added runtime displaying

This commit is contained in:
Markus Dreseler 2013-06-11 19:32:02 +02:00
parent a39c2c8342
commit b075b46c85
5 changed files with 73 additions and 3 deletions

View File

@ -65,6 +65,7 @@ commits to push;
number of pending commits, if any;
* a yellow plus if there is stashed modifications;
* a red star if there is some untracked files in the repository;
* the runtime of the last command, if it has exceeded a certain threshold
* the error code of the last command, if it has failed in some way;
* a smart mark: ± for git directories, ☿ for mercurial, ‡ for svn,
‡± for git-svn, ⌘ for fossil, $ or % for simple user, a red # for root;
@ -132,9 +133,10 @@ You can configure some variables in the `~/.config/liquidpromptrc` file:
* `LP_BATTERY_THRESHOLD`, the maximal value under which the battery level is
displayed
* `LP_LOAD_THRESHOLD`, the minimal value after which the load average is
* `LP_LOAD_THRESHOLD`, the minimal value after which the load average is displayed
* `LP_TEMP_THRESHOLD`, the minimal value after which the temperature average is
displayed
* `LP_RUNTIME_THRESHOLD`, the minimal value after which the runtime is displayed
* `LP_PATH_LENGTH`, the maximum percentage of the screen width used to display
the path
* `LP_PATH_KEEP`, how many directories to keep at the beginning of a shortened
@ -161,6 +163,7 @@ building:
* `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
* `LP_ENABLE_RUNTIME`, if you want to display the runtime of the last command
* `LP_ENABLE_TIME`, if you want to display the time at which the prompt was shown
* `LP_TIME_ANALOG`, when showing time, use an analog clock instead of numeric values
@ -340,3 +343,4 @@ limitation of the Subversion versionning model.
sufficiently complete font on your system.
The [Symbola](http://users.teilar.gr/~g1951d/) font, designed by Georges Douros,
is known to work well.
* Displaying the runtime currently only works with bash

View File

@ -16,6 +16,7 @@
# LP_ERR last error code
# LP_MARK prompt mark
# LP_TIME current time
# LP_RUNTIME runtime of last command
# LP_PS1_PREFIX user-defined general-purpose prefix (default set a generic prompt as the window title)
# Remember that most features come with their corresponding colors,
@ -40,7 +41,7 @@ else
[[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && LP_PS1="${LP_PS1}${LP_VCS}"
fi
# add return code and prompt mark
LP_PS1="${LP_PS1}${LP_ERR}${LP_MARK}"
LP_PS1="${LP_PS1}${LP_RUNTIME}${LP_ERR}${LP_MARK}"
# "invisible" parts
# Get the current prompt on the fly and make it a title

View File

@ -101,6 +101,9 @@ LP_COLOR_TIME="$BLUE"
# Virtualenv
LP_COLOR_VIRTUALENV="$CYAN"
# Runtime
LP_COLOR_RUNTIME="$YELLOW"
# Color maps (battery and load levels)
# Range from 0 (nothing special) to 9 (alert)
LP_COLORMAP_0=""

View File

@ -38,6 +38,7 @@
# 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.
# Markus Dreseler <github@dreseler.de> # Runtime of last command
# Nicolas Lacourte <nicolas@dotinfra.fr> # screen title
# nojhan <nojhan@gmail.com> # Main author.
# Olivier Mengué <dolmen@cpan.org> # Major optimizations and refactorings everywhere.
@ -207,6 +208,7 @@ _lp_source_config()
LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60}
LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-60}
LP_RUNTIME_THRESHOLD=${LP_RUNTIME_THRESHOLD:-2}
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
@ -233,6 +235,13 @@ _lp_source_config()
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
LP_ENABLE_BZR=${LP_ENABLE_BZR:-1}
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
if [[ "$_LP_SHELL_bash" == true ]]
then
LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-1}
else
[[ "$LP_ENABLE_RUNTIME" == 1 ]] && echo Unfortunately, runtime printing for zsh is not yet supported. Turn LP_ENABLE_RUNTIME off in your config to hide this message.
LP_ENABLE_RUNTIME=0
fi
LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
LP_ENABLE_TITLE=${LP_ENABLE_TITLE:-0}
@ -288,6 +297,7 @@ _lp_source_config()
LP_COLOR_DISCHARGING_UNDER=${LP_COLOR_DISCHARGING_UNDER:-$RED}
LP_COLOR_TIME=${LP_COLOR_TIME:-$BLUE}
LP_COLOR_IN_MULTIPLEXER=${LP_COLOR_IN_MULTIPLEXER:-$BOLD_BLUE}
LP_COLOR_RUNTIME=${LP_COLOR_RUNTIME:-$YELLOW}
LP_COLORMAP_0=${LP_COLORMAP_0:-""}
LP_COLORMAP_1=${LP_COLORMAP_1:-$GREEN}
@ -1186,6 +1196,47 @@ _lp_color_map() {
fi
}
###########################
# runtime of last command #
###########################
_LP_RUNTIME_LAST_SECONDS=0
_lp_runtime()
{
[[ "$LP_ENABLE_RUNTIME" != 1 ]] && return
if [[ $_LP_RUNTIME_SECONDS -ge $LP_RUNTIME_THRESHOLD ]]
then
echo -ne "${LP_COLOR_RUNTIME}"
# display runtime seconds as days, hours, minutes, and seconds
[[ "$_LP_RUNTIME_SECONDS" -ge 86400 ]] && echo -ne $(expr ${_LP_RUNTIME_SECONDS} / 86400)d
[[ "$_LP_RUNTIME_SECONDS" -ge 3600 ]] && echo -ne $(expr ${_LP_RUNTIME_SECONDS} % 86400 / 3600)h
[[ "$_LP_RUNTIME_SECONDS" -ge 60 ]] && echo -ne $(expr ${_LP_RUNTIME_SECONDS} % 3600 / 60)m
echo -ne $(expr ${_LP_RUNTIME_SECONDS} % 60)s
echo -ne "${NO_COL}"
fi
}
_lp_reset_runtime()
{
# Compute number of seconds since program was started
_LP_RUNTIME_SECONDS=$(expr $SECONDS - $_LP_RUNTIME_LAST_SECONDS)
# If no proper command was executed (i.e., someone pressed enter without entering a command),
# reset the runtime counter
[ "$_LP_RUNTIME_COMMAND_EXECUTED" != 1 ] && _LP_RUNTIME_LAST_SECONDS=$SECONDS && _LP_RUNTIME_SECONDS=0
# A proper command has been executed if the last command was not related to liquidprompt
[ "$BASH_COMMAND" = _lp_set_prompt ] && _LP_RUNTIME_COMMAND_EXECUTED=0 && return
_LP_RUNTIME_COMMAND_EXECUTED=1
}
if [ "$LP_ENABLE_RUNTIME" = 1 ]
then
# _lp_reset_runtime gets called whenever bash executes a command
trap '_lp_reset_runtime' DEBUG
fi
###############
# System load #
###############
@ -1449,6 +1500,9 @@ _lp_set_prompt()
# right of main prompt: space at left
LP_VENV="$(_lp_sl "$(_lp_virtualenv)")"
# if change of working directory
LP_RUNTIME=$(_lp_sl "$(_lp_runtime)")
if [[ "$LP_OLD_PWD" != "$PWD" ]]; then
LP_VCS=""
LP_VCS_TYPE=""
@ -1536,7 +1590,7 @@ _lp_set_prompt()
PS1="${PS1}${LP_VCS}"
# add return code and prompt mark
PS1="${PS1}${LP_ERR}${LP_MARK}${LP_PS1_POSTFIX}"
PS1="${PS1}${LP_RUNTIME}${LP_ERR}${LP_MARK}${LP_PS1_POSTFIX}"
# "invisible" parts
# Get the current prompt on the fly and make it a title

View File

@ -99,6 +99,14 @@ LP_ENABLE_BZR=1
# Recommended value is 0
LP_ENABLE_TIME=0
# Show runtime of the last command if over LP_RUNTIME_THRESHOLD
# Recommended value is 0
LP_ENABLE_RUNTIME=0
# Minimal runtime to be displayed
# Recommended value is 2
LP_RUNTIME_THRESHOLD=2
# Display the virtualenv that is currently activated, if any
# Recommended value is 1
LP_ENABLE_VIRTUALENV=1