elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.65k stars 299 forks source link

Elvish binding for filtered directory history #1771

Open xiaq opened 7 months ago

xiaq commented 7 months ago

Pedro on the Telegram channel raised the question of whether directory history can be used via an alternative CLI interface - for example, jump-to foo would be the equivalent of typing Ctrl-L, filter by foo and going to the first result.

I think the interactivity of location mode makes it more powerful, but on the other hand in the spirit of programmability it should be trivial for a user to implement a jump-to command if they prefer.

Right now store:dirs exposes directory history, but the filtering functionality is not exposed. It'd make sense to implement, say edit:location:filter-dirs $filter to return filtered directory history.

xiaq commented 7 months ago

The jump-to command could then be implemented like:

fn jump-to {|filter| cd (edit:location:filtered-dirs $filter | take 1)}
krader1961 commented 6 months ago

Should this mimic store:prev-cmd and store:next-cmd where the value is a prefix to be matched? If not, why not? Should those commands have the ability for more powerful matching? Also, I don't think this should be exposed by a hypothetical edit:location:filtered-dirs command. It should be exposed by the store module.