-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Revamp command duration helper/plugin #1906
Conversation
a70f425
to
3a8c78e
Compare
I've just discovered cmd-returned-notify.plugin and now I'm confused why there's two of these...? |
So, |
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 have left a comment. Also, for some reason, this patch does not for me, the preexec function seems to not execute.. Does this work on your end @gaelicWizard ?
475c56f
to
2a1aceb
Compare
2a1aceb
to
d8669e2
Compare
I'm marking this draft b/c I think I'm going to try to just merge with the plugin. Use one function to store the start time, then let the plugin and the theme separately use the same variable for (a) beep, or (b) prompt display. |
6ba524b
to
0e38baf
Compare
21fcd63
to
cf6ef65
Compare
I've had to rebase on my |
569cfeb
to
92175b6
Compare
92175b6
to
6de01a9
Compare
5da7bcd
to
fa5aabe
Compare
fa5aabe
to
0427758
Compare
c4939a3
to
3123f94
Compare
Rebased on current master |
9726068
to
3e3bd4a
Compare
Rebased & ready! |
401e032
to
161a9eb
Compare
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.
LGTM
1c3f5c5
to
71c5a75
Compare
BATS error should be fixed by #2105. |
Calculate the position (from 1 to 12) of the hour hand on the clock emoji used for the _command_duration string. Expressly handle COMMAND_DURATION_COLOR as blank when undefined.
71c5a75
to
0a81577
Compare
Fallback to `$SECONDS` for older versions of _Bash_. Instead of shortcircuiting the definition, just short-circuit the function. This allows the variable to be set later, e.g. on theme change.
Use `$EPOCHREALTIME` (or `$SECONDS`) built-in variable provided by Bash instead of `date +%s`. We're only measuing the difference in seconds, so avoid both the binary invocation as well as the subshell. Alsö, Reduce environmental pollution by not exporting every variable, and unsetting when done. Change variable names to match lib/command-duration Remove `preexec_return_notification()` in favor of `lib/command-duration`'s `_command_duration_pre_exec()`. This should now use the same preexec hook and variables as the theme library `command_duration`. tests: handle nanoseconds
Rename the `theme/command_duration.theme` file as it's not really got anything to do with theming or SCM.
0a81577
to
866e5be
Compare
Description
Combine
themes/command_duration.theme.bash
andplugins/cmd-returned-notify.plugin.bash
, and rewrite them to use$EPOCHSECONDS
(or$SECONDS
on older Bash) while eliminating temporary files on disk.Motivation and Context
Removing the temp file reduces complexity (no need to locate $TMPDIR, read file back), reduces bug surface (what happens if /tmp cleaner runs before prompt returns?), and improves performance (no need to touch the disk!). Adopting
$EPOCHSECONDS
removes entirely the need for subshells or externaldate
invocation, improving performance and reducing points of failure. Sharing the preexec hook reduces total hooks running, and reduces duplicate code.And, of course,
command_duration
didn't work at all on Mac OS X since BSDdate
doesn't support%1N
; now it works perfectly on both Mac and Linux (and BSD!) and doesn't usedate
at all.How Has This Been Tested?
This change is live in my branch on my system now.
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.