Skip to content
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

Implementing HISTTIMEFORMAT in Ksh #797

Open
dnewhall opened this issue Nov 16, 2024 · 0 comments
Open

Implementing HISTTIMEFORMAT in Ksh #797

dnewhall opened this issue Nov 16, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@dnewhall
Copy link

bash has a HISTTIMEFORMAT variable that saves the timestamp for each interactive command that is run and displays the timestamp using its value as a format string when listing the history. This is pretty useful sometimes and could be added to Ksh.

After reading the source, here's what I think needs to be changed to implement this (though am unsure of some details). Presumably someday I'll have the time to code this up and test it, but in the meantime, I'm going to leave this explanation here:

  1. First, increment the history file version number (HIST_VERSION in history.h), so the magic number sequence would now be \201\02
  2. In edit/history.c, add a new byte sequence starting with \203 (since \201 is the undo, and \202 is to set the command number) and continuing for 9 bytes. The bytes following the \203 are the bytes representing the time_t value for the time the following command was run. I think the functions hist_eof, hist_trim, and hist_write are the big ones that need to be changed for this.
  3. Add code that saves the UNIX time when a command is executed using the new byte sequence format before the command is executed by the shell. I'm guessing this would go in either sh_eval or sh_exec in sh/xev.c?
  4. As far as I can tell, all history functions operate on the history file itself, not any buffer in memory? hist_list and co. in edit/history.c would then need to be modified to skip over the new \203 sequences when retrieving/saving parts of the command history.
  5. Add code in bltins/hist.c so hist -l (the b_hist function) can check HISTTIMEFORMAT, retrive the timestamps, and display them using its value as the format.

(Steps 1, 2, and (to a lesser extent) 5 are pretty straightforward, steps 3 and 4 are the ones where my knowledge of the source appears to fail me.)

@McDutchie McDutchie added the enhancement New feature or request label Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants