New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose the command duration via a callback #1029
Comments
I would like to see something like a |
Also, note that the solution used by https://github.com/zzamboni/elvish-modules/blob/master/long-running-notifications.elv has a resolution of seconds. The proposed |
I'd rather we introduce an |
Before #1030 is resolved, I am open to an experimental API that exposes this information as a global, perhaps named |
An I agree that assigning a FWIW, On my primary macOS server using the @zzamboni approach, but using |
I agree that it might be better for precision that the shell itself measures and exposes how much a command took. Display/reporting can then of course be done by hooks. Though honestly, I don't think this is a must - I can't really think of a good use case (other than the kind of thing Finally, a question based on the discussion above: isn't the existing |
No, since the What arguments would be passed to a |
I started working on a resolution for this issue and realized that simply pressing Enter should not affect the recorded duration of the most recent command since no command was executed. Also, introducing an |
I've been using a change that introduces the I am also working on a change to introduce a |
The `edit:command:-duration` variable is the elapsed seconds of the most recently run interactive command. It is currently marked experimental by virtue of a `-` prefix since it might be removed in favor of the command execution callback solution. Related elves#1029
This introduces a $edit:after-command callback. It is called with three arguments: the command line that was run, the duration of that command in seconds, and any error that occurred ($nil if no error occurred). Related elves#1029
The `edit:after-command` hooks are called with a single argument: a pseudo-map with these keys: "command": the command line that was run "duration": the execution duration in seconds "error": any error that occurred ($nil if no error occurred) The `edit:command-duration` variable is the elapsed seconds (as a float64) of the most recently run interactive command. Resolves elves#1029
The `edit:after-command` hooks are called with a single argument: a pseudo-map with these keys: "command": the command line that was run "duration": the execution duration in seconds "error": any error that occurred ($nil if no error occurred) The `edit:command-duration` variable is the elapsed seconds (as a float64) of the most recently run interactive command. Resolves elves#1029
The fish shell has a
$CMD_DURATION
variable which is the number of milliseconds that the last interactive command ran. I use that in my right prompt to show a human friendly duration for the most recently run command. An Elvish user can simulate that via the$edit:before-readline
and$edit:after-readline
hooks but that has problems.First, it requires a lot of effort from the user to produce data that should be provided by the shell.
Second, unless you carefully structure the implementation, similar to https://github.com/zzamboni/elvish-modules/blob/master/long-running-notifications.elv, you won't get even a semi-accurate measurement. Even @zzamboni's carefully written solution is less accurate than it could be because it includes additional overhead that could materially increase the computed duration. A naive user will attempt to save the start time in the
$edit:before-readline
hook and use that in the$edit:after-readline
hook to calculate the duration. Oops! The duration now includes the time between issuing a new prompt and the user pressing [enter].The text was updated successfully, but these errors were encountered: