Repository navigation
Replies: 3 comments 3 replies
|
Great question. Not as described, no -- there's nothing Clink can hook to intercept cmd.exe choosing to exit. Clink itself would like that as well, to clean up history sessions. Your best bet is to do cleanups at the start of the next session. (And name the temp files such that some wildcard can reliably match them and only them, so the cleanup catches everything.) You could configure things to try to catch certain kinds of exit operations, but that's unreliable (e.g. override an Alt-F4 key binding, override any other key bindings that can exit, use clink.onfilterinput() to add a hook that tries to parse the input command and deduce whether "exit" will be executed, etc). |
|
history_db::reap is where Clink cleans up its old history files.
> dir /a ~\appdata\local\clink
...
02/23/2026 02:58 AM 929,602 clink_history
02/23/2026 12:06 AM 500 clink_history_38300
02/22/2026 03:13 PM 77 clink_history_38300.removals
02/22/2026 11:14 AM 0 clink_history_38300~
02/23/2026 02:58 AM 0 clink_history_49396
02/23/2026 02:58 AM 35 clink_history_49396.removals
02/23/2026 02:58 AM 0 clink_history_49396~
...The The Loop over Clink keeps any in-use file locked, which blocks deletion. Since process ids can be reused, it's important for Clink to reap before creating any new history files for the current session, otherwise it could collide with already-existing prior session files. This is a common general pattern for a self-healing cleanup of leaks that can't be cleaned up on exit (e.g. often due to a crash, but more generally due to any situation where exit can't be hooked). There doesn't seem to be a formal name for it, but "self-healing startup" or "startup reconciliation" or "crash-only design" are some descriptive names that are sometimes used (among others). |
|
@jtnord I thought about it more. I retract my claim that there's a way to use locking. There is a way ... but only in native code injected into the command shell process, not using shell scripts or Lua scripts or etc. And that's why it works for Clink -- because Clink is native code injected into the command shell process. I brainstormed several potential solutions that didn't require system configuration (e.g. no scheduled task at system startup), but each of them had at least one race condition somewhere that couldn't be solved without native code being involved. |
Uh oh!
There was an error while loading. Please reload this page.
I would like to write a function that does some work including creating a temporary file that would be valid for the duration of the cmd.exe session (in response to some keystroke etc) .
This much should be relatively easy, but I would like a function to be called before the cmd.exe session terminates so that clean-up tasks can be performed (such as removing the temporary file).
Is there a way to do that?
All reactions