summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Höppner2018-03-11 15:52:48 +0100
committerTill Höppner2018-03-11 15:52:48 +0100
commitf86b963120c8b09c00508bf1a0d787fa7d1888eb (patch)
tree7e4c37b0147c8a376dc7415d1e90384b3387515f
parent9f2d591be17c9de205e73962d420e424183cb5ad (diff)
downloadzsh-f86b963120c8b09c00508bf1a0d787fa7d1888eb.tar.gz
zsh-f86b963120c8b09c00508bf1a0d787fa7d1888eb.tar.xz
zsh-f86b963120c8b09c00508bf1a0d787fa7d1888eb.zip
Prettier duration printing
-rw-r--r--conf.d/60-prompt.zsh34
1 files changed, 33 insertions, 1 deletions
diff --git a/conf.d/60-prompt.zsh b/conf.d/60-prompt.zsh
index 1ae2531..66146a5 100644
--- a/conf.d/60-prompt.zsh
+++ b/conf.d/60-prompt.zsh
@@ -1,6 +1,9 @@
bindkey -e # emacs-style keybindings
setopt autocd
+# last line without newline terminator
+# is swallowed if this is absent
+setopt prompt_sp
autoload -U zmv
@@ -21,6 +24,25 @@ elapsed() {
echo $(($(timestamp) - $command_start_time))
}
+humanize_duration() {
+ # ORS= disables the trailing newline
+ command awk -v ORS= '
+ function hmTime(time, stamp) {
+ split("h:m:s:ms", units, ":")
+ for (i = 2; i >= -1; i--) {
+ if (t = int( i < 0 ? time % 1000 : time / (60 ^ i * 1000) % 60 )) {
+ stamp = stamp t units[sqrt((i - 2) ^ 2) + 1] " "
+ }
+ }
+ if (stamp ~ /^ *$/) {
+ return "0ms"
+ }
+ return substr(stamp, 1, length(stamp) - 1)
+ }
+ { print hmTime($0) }
+ '
+}
+
duration=0
command_start_time=$(timestamp)
# called just before line is evaluated
@@ -64,6 +86,16 @@ left_prompt() {
echo -n "@$(hostname | tr -d '\n') "
fi
+ if test -n "$IN_NIX_SHELL"; then
+ zcol "$fg[cyan]"
+ echo -n "nix "
+ fi
+
+ if test -n "$IN_BWRAP"; then
+ zcol "$fg[cyan]"
+ echo -n "bwrap "
+ fi
+
if test -n "$DOCKER_HOST"; then
zcol "$fg[cyan]"
echo -n "$(basename "$DOCKER_HOST") "
@@ -91,7 +123,7 @@ right_prompt() {
command_start_time=$(timestamp)
if (($duration > 0.99)); then
zcol "$fg_bold[cyan]"
- printf "%.1fs" "$duration"
+ humanize_duration <<<"$(( $duration * 1000 ))"
fi
zcol "$reset_color"