d4c74690b61b74e317410df3b80b784891ab55ed

Author
Robert Strack <robert.strack@gmail.com>
Committer
Robert Strack <robert.strack@gmail.com>
Date

Message

increased timer's pecision

Diff

 1diff --git a/plugins/timer/timer.plugin.zsh b/plugins/timer/timer.plugin.zsh
 2index ee2cb66c14ce981a6ba92ac47ebe8571b07cc1e4..729dd3ee261f22273b8be8b9e08be26c82da9d61 100644
 3--- a/plugins/timer/timer.plugin.zsh
 4+++ b/plugins/timer/timer.plugin.zsh
 5@@ -1,14 +1,25 @@
 6+__timer_current_time() {
 7+  perl -MTime::HiRes=time -e'print time'
 8+}
 9+
10+__timer_format_duration() {
11+  local mins=$(printf '%.0f' $(($1 / 60)))
12+  local secs=$(printf '%.1f' $(($1 - 60 * mins)))
13+  local duration_str=$(echo "${mins}m${secs}s")
14+  echo "\`${duration_str#0m}"
15+}
16+
17 preexec() {
18-  __timer_cmd_start_time=$(date '+%s')
19+  __timer_cmd_start_time=$(__timer_current_time)
20 }
21 
22 precmd() {
23-  if [ -n "$__timer_cmd_start_time" ]; then
24-    local cmd_end_time=$(date '+%s')
25+  if [ -n "${__timer_cmd_start_time}" ]; then
26+    local cmd_end_time=$(__timer_current_time)
27     local tdiff=$((cmd_end_time - __timer_cmd_start_time))
28     unset __timer_cmd_start_time
29-    local tdiffstr="$((tdiff / 60))m$((tdiff % 60))s"
30-    local cols=$((COLUMNS - ${#tdiffstr#0m} - 2))
31-    echo -e "\033[1A\033[${cols}C \`${tdiffstr#0m}"
32+    local tdiffstr=$(__timer_format_duration ${tdiff})
33+    local cols=$((COLUMNS - ${#tdiffstr} - 1))
34+    echo -e "\033[1A\033[${cols}C ${tdiffstr}"
35   fi
36 }