Replies: 1 comment 11 replies
-
Use a variable to remember the old directory. local old_dir
local function detect_dir_change()
local new_dir = os.getcwd()
if new_dir ~= old_dir then
print("DIR CHANGED:", old_dir, "->", new_dir)
old_dir = new_dir
end
end
clink.onbeginedit(detect_dir_change)
It sounds like you want Lua callbacks in the middle of the CMD batch language parser and interpreter. It sounds like you want CMD to execute That isn't possible because the CMD batch language parser and interpreter is a closed system that Clink cannot penetrate. The order is this:
Clink cannot "hook" into the internals of the batch scripting language. And even if it could, it should not: because if it did then that would create compatibility problems, because Clink would be able to change how batch scripts work and execute. Clink is currently 100% compatible with existing batch scripts, but if it could allow Lua to run during batch scripts (which it can't -- there are no hooks from CMD to facilitate that) then Clink would no longer be compatible with existing batch scripts. That would be a major problem. If you're trying to get CMD to delay expansion of environment variables, then that's a CMD thing and has nothing to do with Clink. You can learn more about delayed expansion by referring to CMD documentation, or by using internet searches (or by asking AI, but be prepared for the answers to be misleading and only half accurate...). Here is an article that's a great tutorial on using delayed expansion: How to Enable and Use Delayed Expansion in Batch Script. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
Can there be a hook that can respond to directory changes (i.e. probably hooking SetCurrentDirectoryW)?
Motivation
Current implementations require use of either
clink.onbegineditorclink.onendeditto check if directory changes. These face problems like:cd .. && echo %MY_CWD%) would print the previous value of MY_CWD and then updating on next prompt start/end. I expect the flow to be:cd -> callbacks -> echoBeta Was this translation helpful? Give feedback.
All reactions