From 65c428525d49bbfb3b1c32b900360685365756e9 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Thu, 26 Mar 2015 00:25:54 -0400 Subject: [PATCH] Added runtime to zsh prompts --- README.md | 1 - liquidprompt | 44 +++++++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index abe05fe..f60d88c 100644 --- a/README.md +++ b/README.md @@ -352,7 +352,6 @@ version 3](LICENSE). * The analog clock requires a Unicode-aware terminal and at least a 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. ## Authors diff --git a/liquidprompt b/liquidprompt index dc80b81..58b7285 100755 --- a/liquidprompt +++ b/liquidprompt @@ -46,7 +46,7 @@ # Rolf Morel # "Shorten path" refactoring and fixes # Thomas Debesse # Fix columns use. # Yann 'Ze' Richard # Do not fail on missing commands. -# Austen Adler # ZSH RPS1 +# Austen Adler # ZSH RPS1, ZSH runtime # See the README.md file for a summary of features. @@ -297,11 +297,7 @@ _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; then - LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-1} - else - LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-0} - fi + LP_ENABLE_RUNTIME=${LP_ENABLE_RUNTIME:-1} LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1} LP_ENABLE_SCLS=${LP_ENABLE_SCLS:-1} LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0} @@ -417,11 +413,6 @@ command -v screen >/dev/null ; _lp_bool _LP_ENABLE_SCREEN $? command -v tmux >/dev/null ; _lp_bool _LP_ENABLE_TMUX $? $_LP_ENABLE_SCREEN || $_LP_ENABLE_TMUX ; _lp_bool _LP_ENABLE_DETACHED_SESSIONS $? -if [[ "$LP_ENABLE_RUNTIME" == 1 ]] && ! $_LP_SHELL_bash; then - 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 - # If we are running in a terminal multiplexer, brackets are colored if [[ "$TERM" == screen* ]]; then LP_BRACKET_OPEN="${LP_COLOR_IN_MULTIPLEXER}${LP_MARK_BRACKET_OPEN}${NO_COL}" @@ -1345,18 +1336,33 @@ _lp_runtime() fi } +if [ "$_LP_SHELL_zsh" ] ; then + function precmd() { + if [ $timer ]; then + export _LP_RUNTIME_SECONDS=$(($SECONDS - $timer)) + unset timer + fi + } + + function preexec() { + export timer=${timer:-$SECONDS} + } +fi + _lp_reset_runtime() { - # Compute number of seconds since program was started - _LP_RUNTIME_SECONDS=$((SECONDS - _LP_RUNTIME_LAST_SECONDS)) + if $_LP_SHELL_bash; then + # Compute number of seconds since program was started + _LP_RUNTIME_SECONDS=$((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 + # 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 Liquid Prompt - [ "$BASH_COMMAND" = _lp_set_prompt ] - _LP_RUNTIME_COMMAND_EXECUTED=$? + # A proper command has been executed if the last command was not related to Liquid Prompt + [ "$BASH_COMMAND" = _lp_set_prompt ] + _LP_RUNTIME_COMMAND_EXECUTED=$? + fi } if [ "$LP_ENABLE_RUNTIME" = 1 ]