powerlevel10k
powerlevel10k copied to clipboard
Keep cammand_execution_time on the old prompt even with transient prompt
I turn on transient prompt and it looks good! Yet, I want to keep command execution time for every time-consuming command. As you can see in the first figure, the system only keeps the execution time for the last executed 'sleep 3' in the prompt, but it will vanish right after I enter a new line (just like what happens to the first 'sleep 3'). Do you know how I can do it? This is my snapshot of the Transient code:
Search "p10k-on-pre-prompt" in issues. There are solutions to similar requests.
Oh, Thanks, I found that turning off POWERLEVEL9K_TRANSIENT_PROMPT makes it work. Is it possible to make the execution time shown on the same command line, like 'sleep 3', instead of showing it on the next line?
Yes, it's possible. Check the other issues.
@Sam5566, you cannot move or add segments on-the-fly but you can add segments in multiple places (e.g. two different lines) and then hide and show them accordingly.
What I think you want is to have a second command_execution_time after a newline on in your right prompt segments. This will show execution time twice.
You can then use the hooks to…
function p10k-on-pre-prompt() {
# …hide line 2 time before showing a new prompt while showing line 1 time and…
p10k display '2/right/command_execution_time=hide' '1/right/command_execution_time=show'
}
function p10k-on-post-prompt() {
# …show line 2 time after pressing enter and hide line 1 time
p10k display '2/right/command_execution_time=show' '1/right/command_execution_time=hide'
}
You can do this with as many segments as you like no matter on which side they are. Make sure to read p10k help display for how to select the right segments.
Hi everyone.
I think there's a bit of confusion about command_execution_time.
From what I understood, command_execution_time represents "how long the command took to run".
I think I also understood that the p10k-on-post-prompt function is executed after pressing enter to launch a command, but before the command is run. This is also evident by the fact that the second line in the transient prompt is printed immediately, even if the command is a sleep X. Only the "new" prompt will be printed after the command is executed.
I haven't found any ways to show "how long the command took to run" (i.e. command_execution_time) on the second line that we want to keep in the transient prompt.