romkatv / powerlevel10k

A Zsh theme
MIT License
46.77k stars 2.2k forks source link

Keep cammand_execution_time on the old prompt even with transient prompt #2694

Open Sam5566 opened 6 months ago

Sam5566 commented 6 months ago

image

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: image

romkatv commented 6 months ago

Search "p10k-on-pre-prompt" in issues. There are solutions to similar requests.

Sam5566 commented 6 months ago

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?

romkatv commented 6 months ago

Yes, it's possible. Check the other issues.

Syphdias commented 5 months ago

@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.