\D{format} yields the result of calling strftime(3) with the provided
format and the current time.
When PS4 can use this, it will enable us to easily generate timestamps
when tracing script execution.
Differential D35840
sh: implement PS1 \D to print current time pstef on Jul 18 2022, 8:38 AM. Authored by Tags None Referenced Files
Subscribers
Details
\D{format} yields the result of calling strftime(3) with the provided When PS4 can use this, it will enable us to easily generate timestamps
Diff Detail
Event TimelineComment Actions Place the result of strftime() in the right place instead of always at the beginning of the buffer. Comment Actions A little unfortunate to have these strange backslash sequences spread out further, but it's nothing that bash doesn't do.
Comment Actions
In a way, this has nothing to do with bash. I want sh PS4 to be able to generate some kind of timestamps when executing a script with tracing on. The way bash does it is just a convention which I think is not worth diverging from.
Comment Actions The more POSIX-like way would be to add some level of command substitution to expandstr() (ensuring set -x doesn't apply to the nested command) and put in something like $(date +%s) in PS4. However, this is slower and harder to implement. It is also more flexible.
Comment Actions Code is OK like this.
Comment Actions In this iteration I tried to address all new feedback. Comment Actions When I was looking at this code today, I thought that the unconditional memccpy() is a bit wasteful in the \D{} case, because the one copied byte is a special case and when it's noticed, the copied byte is overwriten by strcpy() with "%X". Comment Actions Minutes after posting the previous version, I thought about handling the rare corner case when strftime() returns 0. Comment Actions Back out the previous update. |