larkery / zsh-histdb

A slightly better history for zsh
MIT License
1.25k stars 74 forks source link

[Feature request] Store paths used in a certain command #105

Closed NyaomiDEV closed 2 years ago

NyaomiDEV commented 3 years ago

When using ZSH with autosuggestions, it is possible that it will autosuggest invalid commands. An example: image

If histdb kept track of paths used in a certain command, we could then modify ZSH_AUTOSUGGEST_STRATEGY so that the lookup checks that all the directories and files exist before suggesting a particular command.

The friendly interactive shell does just this, and it is wonderful.

larkery commented 2 years ago

I am old-fashioned and don't use autosuggestions so I am not going to work on this myself. However if it is a useful thing you could implement it and if it didn't add too much tangle I would incorporate it.

Is your proposal here that whenever anyone runs a command we check every argument to see whether it exists as a file at the time, and keep a list of every file that ever was, so that then when the auto suggestion device is suggesting something we can check if it was once an existing file but now isn't and then not suggest it?

I think you might be able to get 80% of the usefulness at lower hassle by making the autosuggest thing guess which arguments are files (does it have a slash in). This will have false-positives for a few things (e.g. origin/master, urls) and false-negatives for bare filenames, but you could special case those out.

Or maybe even know which arguments are files by talking to the completion system instead? That is aware which arguments should be filenames somehow.

NyaomiDEV commented 2 years ago

Well, better late than never, as they say.

First off, sadly I am not a ZSH genius and I really fail to make plugins for it. Would've loved it tho; then, I guess that a reliable way of implementing it is to do it just like fish does it: check all arguments for files and directories upon command execution, then when autosuggesting check the retrieved paths: if they exist then autosuggest, if they do not, then scrap it for the time being