summaryrefslogtreecommitdiff
path: root/conf.d
diff options
context:
space:
mode:
Diffstat (limited to 'conf.d')
-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"