chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.44k stars 135 forks source link

Why are commands starting with "history" always excluded from history? #650

Closed char101 closed 1 month ago

char101 commented 1 month ago

Hi,

When running commands with name history, e.g. history.cmd, history.py, it is always excluded from the command history.

> R:

> history.cmd

echo hello
hello

> history
    1  R:
chrisant996 commented 1 month ago

Yes. See the documentation at Saved Command History. The "Note" explains the behavior.

char101 commented 1 month ago

If the first word in the line matches one of the words in the history.dont_add_to_history_cmds

I would expect that words are separated by whitespaces not dot though.

I think the only command that can contain dot is the ECHO command. Thus ECHO. is still ECHO but history.cmd is a different thing with history.

char101 commented 1 month ago

I think rather than isalnum, the check should compare the char to space or tab

https://github.com/chrisant996/clink/blob/0369d2d39335bea4097e59eba61c0e601a2d1136/clink/app/src/host/host.cpp#L1230

chrisant996 commented 1 month ago

If the first word in the line matches one of the words in the history.dont_add_to_history_cmds

I would expect that words are separated by whitespaces not dot though.

I think the only command that can contain dot is the ECHO command. Thus ECHO. is still ECHO but history.cmd is a different thing with history.

I can understand that desire.

That's specifically not how this is designed. It's designed to intentionally ignore extensions (like argmatchers do in Clink), so that one doesn't have to add foo, foo.exe, foo.bat, foo.cmd, foo.pl, etc to cover all the variations of a doskey alias or built-in command or scripts or external programs that shouldn't be added to history.

It's been like this for 4 years. Since there hasn't been any feedback about it until now, changing it at this point introduces risk of breaking other people's usage preferences. Every time I've made a change like this that seemed simple and like "what could possibly go wrong?" multiple regressions were caused unexpectedly.

I'm potentially open to changing the behavior someday, but that's risky and isn't something I would do quickly or lightly.

chrisant996 commented 1 month ago

One workaround you could do is to create a different alias such as doskey hist="c:\program files\clink\clink_x64.exe" history $*, and change clink.dont_add_to_history_cmds to hist exit. Then it wouldn't prevent history.cmd from being added to the history, and you could use hist instead of history for listing/manipulating the history.

I recognize it isn't the same as what you'd like. It's the closest workaround I can think of, though.

char101 commented 1 month ago

Thank you for the explanation.

I just realize that for normal executable the extension part is optional, thus typing cmd is the same as typing cmd.exe, cmd.cmd, and so on, so I can understand that ignoring the extension is correct in this case.

I think I will choose the simplest option and set history.dont_add_to_history_cmds to empty list.

chrisant996 commented 1 month ago

I just realize that for normal executable the extension part is optional, thus typing cmd is the same as typing cmd.exe, cmd.cmd, and so on, so I can understand that ignoring the extension is correct in this case.

Yes, that's why it's designed to behave the way it currently does.

I agree that on a case by case basis, there can be particular usages where the behavior feels more like a drawback than a benefit. I think that making the behavior more complicated adds more cost and documentation and complexity than is really worth it for this minor convenience feature (e.g. more complicated behavior could allow regular expressions, or conditionally allow ignoring extensions or paths, or etc).

Clearing the list seems like a good compromise.