Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and conscise display of $CMD_DURATION in right prompt #13

Merged
merged 2 commits into from
Apr 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion fish_right_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function fish_right_prompt
else
set_color blue
end
printf ' < %s' (_convertsecs (math $cmd_duration / 1000))
printf ' (%s)' (__print_duration $cmd_duration)
set_color 666666
printf ' < %s' (date +%H:%M:%S)
set_color normal
Expand Down Expand Up @@ -60,6 +60,26 @@ function _is_multiplexed
echo $multiplexer
end

function __print_duration
set -l duration $argv[1]

set -l millis (math $duration % 1000)
set -l seconds (math -s0 $duration / 1000 % 60)
set -l minutes (math -s0 $duration / 60000 % 60)
set -l hours (math -s0 $duration / 3600000 % 60)

if test $duration -lt 60000;
# Below a minute
printf "%d.%03ds\n" $seconds $millis
else if test $duration -lt 3600000;
# Below a hour
printf "%02d:%02d.%03d\n" $minutes $seconds $millis
else
# Everything else
printf "%02d:%02d:%02d.%03d\n" $hours $minutes $seconds $millis
end

function _convertsecs
printf "%02d:%02d:%02d\n" (math -s0 $argv[1] / 3600) (math -s0 (math $argv[1] \% 3600) / 60) (math -s0 $argv[1] \% 60)
end