From fd1020cf245b4f8930fe944816297610b7ac5e5e Mon Sep 17 00:00:00 2001 From: lelgenio Date: Wed, 15 Feb 2023 17:30:43 -0300 Subject: [PATCH] fish: time command execution --- user/fish/fish_prompt.fish | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/user/fish/fish_prompt.fish b/user/fish/fish_prompt.fish index 79ba47d..0fec382 100644 --- a/user/fish/fish_prompt.fish +++ b/user/fish/fish_prompt.fish @@ -118,6 +118,34 @@ function fish_git_prompt end +############################################################ +# Program time indicator +############################################################ + +function __fish_prompt_set_last_command_start --on-event fish_preexec + set -g __fish_prompt_last_command_start (date +%s.%N) +end + +function __fish_prompt_set_last_command_end --on-event fish_postexec + set -g __fish_prompt_last_command_end (date +%s.%N) +end + +function fish_program_time_prompt + if test -z "$__fish_prompt_last_command_start" + or test -z "$__fish_prompt_last_command_end" + return + end + + set -l diff (math $__fish_prompt_last_command_end - $__fish_prompt_last_command_start) + set -l diff (math "round ($diff * 100) / 100") + + if test "$diff" -gt 1 + _fish_prompt_normal " took " + _fish_prompt_warn (env LC_ALL=C printf "%.02f" "$diff") + end +end + + ############################################################ # Vi mode indicator ############################################################ @@ -175,6 +203,8 @@ function fish_prompt fish_git_prompt + fish_program_time_prompt + # Line break echo