Skip to content

Commit c20eaee

Browse files
author
js402882
committed
Conscise display of $CMD_DURATION in right prompt
1 parent 3072990 commit c20eaee

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

fish_right_prompt.fish

+20-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function fish_right_prompt
1313
else
1414
set_color blue
1515
end
16-
printf ' < %s' (_convertsecs (math $cmd_duration / 1000))
16+
printf ' (%s)' (__print_duration $cmd_duration)
1717
set_color 666666
1818
printf ' < %s' (date +%H:%M:%S)
1919
set_color normal
@@ -60,6 +60,23 @@ function _is_multiplexed
6060
echo $multiplexer
6161
end
6262

63-
function _convertsecs
64-
printf "%02d:%02d:%02d\n" (math $argv[1] / 3600) (math (math $argv[1] \% 3600) / 60) (math $argv[1] \% 60)
63+
function __print_duration
64+
set duration $argv[1]
65+
66+
set -l millis (math $duration % 1000)
67+
set -l seconds (math -s0 $duration / 1000 % 60)
68+
set -l minutes (math -s0 $duration / 60000 % 60)
69+
set -l hours (math -s0 $duration / 3600000 % 60)
70+
71+
if test $duration -lt 60000;
72+
# Below a minute
73+
printf "%d.%03ds\n" $seconds $millis
74+
else if test $duration -lt 3600000;
75+
# Below a hour
76+
printf "%02d:%02d.%03d\n" $minutes $seconds $millis
77+
else
78+
# Everything else
79+
printf "%02d:%02d:%02d.%03d\n" $hours $minutes $seconds $millis
80+
end
6581
end
82+

0 commit comments

Comments
 (0)