Artificial intelligent assistant

Show time elapsed since I started last command in prompt Is there a way to show time elapsed since I started last command? I found this: PS1 prompt to show elapsed time but that will show time elapsed since last command finished until the new command finished. My idea is to somehow force the prompt to add `time` _before_ every command I type in, and the format it in some nice way. Something like this: $ ls . .. Last command took 0.001s $

You need two functions and a timer. First function is executed just after you hit enter on the command line, but before actual command starts. Second function is executed after command finishes, but before prompt is displayed. Timer just counts seconds since you start the shell. In `zsh` these three hooks are called `precmd`, `preexec` and `SECONDS` respectively.

In `bash` timer's name is the same, function `precmd` become a variable `PROMPT_COMMAND`, but unfortunately function `preexec` is missing, so you need to write it yourself (nothing extremely challenging, but not trivial either) or install already written hook from external source, e.g. <

Now we just need to glue all pieces together, minimal code looks like this:


preexec() {
cmd_start="$SECONDS"
}

precmd() {
local cmd_end="$SECONDS"
elapsed=$((cmd_end-cmd_start))
PS1="$elapsed "
}


Put everything in `.bashrc`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e40d0d5210e32807bc2e3c200e61b180