SHARE
TWEET

Untitled

a guest Oct 12th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _prompt_arthur_pwd=''
  2. _prompt_arthur_start_time=0
  3. _prompt_arthur_elapsed_printed=''
  4.  
  5. prompt_arthur_print_elapsed_time() {
  6.   $_prompt_arthur_elapsed_printed && return
  7.  
  8.   local t=$(( SECONDS - _prompt_arthur_start_time ))
  9.   local h m s r
  10.  
  11.   if (( t >= 3600 )); then
  12.     h=$(( t / 3600 ))
  13.     r=$(( t % 3600 ))
  14.     m=$(( r / 60 ))
  15.     s=$(( r % 60 ))
  16.     print -P "%B%F{red}elapsed time ${h}h${m}m${s}s%b"
  17.   elif (( t >= 60 )); then
  18.     m=$(( t / 60 ))
  19.     s=$(( t % 60 ))
  20.     print -P "%B%F{yellow}elapsed time ${m}m${s}s%b"
  21.   elif (( t > 1 )); then
  22.     print -P "%B%F{green}elapsed time ${t}s%b"
  23.   fi
  24.   _prompt_arthur_elapsed_printed=true
  25. }
  26.  
  27. function prompt_arthur_precmd {
  28.   setopt LOCAL_OPTIONS
  29.   unsetopt XTRACE KSH_ARRAYS
  30.   _prompt_arthur_pwd=$(prompt-pwd)
  31.   prompt_arthur_print_elapsed_time
  32. }
  33.  
  34. function prompt_arthur_preexec {
  35.   _prompt_arthur_start_time=$SECONDS
  36.   _prompt_arthur_elapsed_printed=false
  37. }
  38.  
  39. function prompt_arthur_setup {
  40.   setopt LOCAL_OPTIONS
  41.   unsetopt XTRACE KSH_ARRAYS
  42.   prompt_opts=(cr percent sp subst)
  43.  
  44.   autoload -Uz add-zsh-hook
  45.   add-zsh-hook preexec prompt_arthur_preexec
  46.   add-zsh-hook precmd prompt_arthur_precmd
  47.  
  48.   _prompt_arthur_pwd=''
  49.  
  50.   PROMPT='%B${_prompt_arthur_pwd}%b '
  51.   RPROMPT=''
  52. }
  53.  
  54. prompt_arthur_setup "$@"
RAW Paste Data
Top