srsudar / eg

Useful examples at the command line.
MIT License
1.8k stars 98 forks source link

Bash completion #89

Open Skabit opened 3 years ago

Skabit commented 3 years ago

Hi @srsudar,

Please add bash completion (TAB) for eg:

eg fi<TAB>
eg find

I don't know how is the best way to implement that functionality, but as eg is a terminal tool the tab completion is a necessary feature.

srsudar commented 3 years ago

Hmm good idea. I'll do some investigating.

Skabit commented 3 years ago

@srsudar thanks for the interest. I'm now a really fan of eg

happytree718 commented 1 year ago

@srsudar,

I have been looking into the possibility of adding tab completion functionality to eg, and I've come up with a potential approach that I'd like to share.

Instead of using actual bash-completion (which could complicate the installation process and may not work across all platforms), I'm proposing a pseudo-completion scheme implemented at the Python level.

Here's how it would work: when a user types a partial command (like eg fi) and hits Enter, the program would scan through the examples-dir and custom-dir to find matches. If there are multiple prefix matches, it would print out all the matches to the users, allowing them to see their options. If there is an exact match or only one prefix match, it would directly execute it.

While this approach wouldn't provide the same experience as traditional tab completion, I believe it would be a helpful feature to improve the usability of eg. It would enable users to discover available commands more easily and complete their desired command without needing to type it out fully.

I'd be happy to work on implementing this feature if you think it would be a beneficial addition to the project. This is indeed a very helpful tool, thanks!

Looking forward to your thoughts,

Erwin

srsudar commented 1 year ago

I had forgotten about this issue! Thanks for resurrecting.

I think that the enter approach (as opposed to tab completion) would be a bit too unlike regular tab completion.

The easiest solution to me seems like including a zsh/sh function that uses eg --list and parses the output and passes it to `fzf link. That way fzf can handle all the tab completion stuff. Not quite as fancy as normal tab completion but it seems easier to me.