This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 950
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds option to reset time segment on execute
- Loading branch information
Syphdias
committed
Mar 14, 2019
1 parent
fabc54a
commit fb1ef54
Showing
2 changed files
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intentionally that for accept-line you allow user-defined widgets but for reset-prompt you don't? What's the logic behind it?
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason, I picked up
.reset-prompt
from your code without knowing the details about the differences, tbh. I assume something like\
orcommand
to not use aliases.I'm not sure which one to prefer
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't know what's the best practice here -- allow overrides or not? But at least be consistent.
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P9K_TIME_RESET_ON_EXEC
has suboptimal UX.The simplest model of
P9K_TIME_RESET_ON_EXEC
for users to understand is turningtime
segment into "start time of the command". However, the code fails to deliver on this promise if the user has boundaccept-command
to some key other than[ENTER]
.In addition,
time
segment on the last promot also don't conform to the model because in theretime
displays "end time of the previous command", unlike in all other prompts. To avoid breaking the model, the current prompt must either have notime
(only previous prompts have "start time of the command") or the time must be ticking, indicating that the start of the command is moving into the future.Another problem is that
[ENTER]' isn't the only thing that accepts commands. There is
Ctrl+O`, which is quite useful, and might be other things I don't know about.fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to use the real-time version for a while now. It is really annoying that it breaks going through the history. Here an example of what I mean:
Two examples
<press up (to get echo)><wait for prompt to rerender><press up (to get ls)>
this will get
echo bar
since your current command starts withecho
<press up twice (to get ls)><wait for prompt to rerender><press up (to get echo bar)>
this will get
ls /
Regarding the UX of
P9K_TIME_RESET_ON_EXEC
:Looking at
bindkey
I found these which I could rebind as well. If there is a keybind missing people can always report it.I'm not sure what you mean by that. Do you want to say that it should be either the time the command ended or always the time the command started and not a hybrid? If so, playing devil's advocate here, you could also say, since you didn't execute a command yet the time shouldn't tick either but not displayed because you didn't execute a command yet.
For me, and this is a very subjective view, the reset on accept-line is the perfect hybrid. If you scroll up, you see the start of execution and for the last one, you see when it ended. The ticking is a nice addition, to turn on or off.
So two questions. How would you tackle the UX side? And do you think the history bug can be fixed (that imho is a bigger threat to UX)?
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I'm working on something else right now but I might get back to this later.
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I fixed the history thing here: https://github.com/romkatv/zsh/tree/gentle-reset-prompt. Diff against upstream: zsh-users/zsh@master...romkatv:gentle-reset-prompt.
My changes do two things. First, they add
-W
tozle widget
builtin that causesLASTWIDGET
to be restored after the call. Second, it forcesreset-prompt
widget to always be called with this flag.Before this change
up-line-or-beginning-search
(this is what your '[up]key is bound to) was broken, as you've aptly noticed. It was losing its context not only on explicit
zle rest-prompt` calls but also when background jobs complete (background job completion will also wipe your completion menu off the screen). This change fixes the bug and also fixes a long-standing problem that I had with user-defined widgets (see below).I want my
[up]
key to behave asup-line-or-beginning-search
with local history turned on, so that it doesn't see history from other sessions, and my[ctrl+up]
key to behave asup-line-or-beginning-search
with local history turned off, so that it does see history from other sessions. This is very difficult to achieve. The only solution I found is to forkup-line-or-beginning-search
and edit its source code (you probably noticed I fork code a lot). You can see it in my .zshrc. With the new-W
flag that I added tozle
this problem has a clear solution. Like this:I also tried to fix the bug with completion menu disappearing but the code in there is really complex, so I gave up after an hour.
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romkatv Quick note: I haven't forgotten about this. I'm currently just a little short on time :(
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I started a thread with zsh-workers about upstreaming my fix for history being broken by
reset-prompt
. See https://www.zsh.org/mla/workers//2019/msg00204.html.fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: After you've forked the code from p10k, I've implemented several fixes.
exec zsh
. If you run it several times, you can have many of the same rogue processes hanging around. This is fixed in p10k.fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romkatv, thx for letting me know. Currently, I put this code into the time segment but I think this can be useful for more than just this setting to rerender the prompt (as you did for
background_jobs
as well, I think).Maybe I will need it to fix #1196 and #1201 (though I will try to do it without it)
Reminds me, I should join the zsh mailing list...
fb1ef54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about
zle-line-finish
. Might be useful. Quick proof of concept (requires ZSH >= 5.3):