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
Support getting the current unix timestamp with status
#10093
Comments
I have a branch lying around somewhere that adds a variable. I think I called it $EPOCH (bash has $EPOCHSECONDS and $EPOCHREALTIME, the latter was added after someone wanted to have nanoseconds). Looking at it again I'd probably call it $fish_time so it's less jargony and doesn't step on anyone's toes (what if someone has already made a variable called $EPOCH?). |
Personally I'd prefer a builtin subcommand over polluting the variable namespace even more, especially with this kind of magic variable that isn't really a variable but more of a function call. |
There's not really a fitting builtin to add it - The time is not something that happens inside of fish's own code. It is a universal thing. Every other builtin fits even less. Adding a variable with a fish_ prefix is not really a big deal. It's fine. Or we refocus status somewhat and add this and possibly a set -l time (status current-time 2>/dev/null; or date +%s)
set -l os (status operating-system 2>/dev/null; or uname) to have backwards-compatible code to versions before that was introduced. With variables you'd have to fiddle with |
I wonder when |
Too slow is relative: 7ms to grab the current time is definitely too slow, and grabbing the time is a pretty common thing with code related to shells and prompts. However it's likely never a bottleneck. The point of this suggestion is that we might not need to make our machines do all the work of spawning a process, setting up stdio/pipes, parsing the arguments and waiting for the output all to basically call You can make a slippery-slope argument about this, but "inlining" very common things is a good thing to do. Time functions are definitely lacking here. IMO just including a way to grab the UNIX timestamp, and maybe the ISO 8601 timestamp, is all we should add. If you need anything more custom then use |
To me Maybe we could add a |
This is extremely easy to implement and can be used for all sorts of durations. Fixes fish-shell#10093
I second this proposition. Currently, the only way to have the time in one's command prompt is to have Some kind of a wrapper for |
Depending on the various incarnations of
Isn't fish the very same shell that eschews basic subshell functionality (how's |
@mralusw If you want to profile a script, use Other than that I would appreciate further comments without the digs at other issues, thank you very much. |
That's very useful but it only handles profiling entire scripts. If you want to write a script to benchmark something else, or want to time a fragment of the current script, having a way to get timestamps is not easily replaceable.
I was digging at another comment, not another issue. But the point is that if you design your shell to avoid |
You can profile specific code - This will also work for functions, provided they are defined in that fish (e.g. autoloaded). And in general, a full profile is more useful for, well, profiling, than just the timestamp.
And that is why this issue is still open. The question is mostly where to put the functionality - $EPOCHREALTIME is a mouthful and quite jargony, a
Regardless, I would appreciate if you could just not dig at all. |
I agree, I was pointing out a separate use case. Is there any overhead for having a builtin vs a variable? AFAICT there isn't. Other than that, at this point it seems it's (1) a string function (so it could be a
There were also digs at |
Fish is a great shell with a lot of builtin utilities. I was surprised to see that there was no built-in way to get the current unix timestamp with fish. For context, I'm using a function that runs on the
fish_postexec
event and I'd like to record the current time of the command somewhere.I can obviously just do
date +%s
, but this is surprisingly heavyweight:Compared to a built-in like
status
:5 microseconds vs 7.15 milliseconds is a big difference - that's 1430x faster!
The
status
command is described as a way to query fish runtime information. The current unix timestamp seems like it would fall into the category of "fish runtime information", so I'm proposing to add astatus current-timestamp
orstatus execution-timestamp
command to return a simple UNIX timestamp, the same asdate +%s
but far faster.There are quite a few usages of
date +%s
in Fish files that you can find on Github, and even more general usages ofdate
.We shouldn't look to emulate/replace
date
, but if there is a super-common use-case like grabbing the unix timestamp that currently requires usingdate
, perhaps it's worth adding it as a builtin?The text was updated successfully, but these errors were encountered: