I developed a gem that includes an executable script (application file in rubygems terms). When invoking, I’d like to complete filenames in a given directory (which is not the current working dir), like so:
foo edit my<tab>
gets expanded to:
foo edit myfile
What I could do is include a script that installs shell completions. If that’s the only solution—fine. But I was wondering if there’s a way I can free users from the additional step and include completions in my gem directly.
So: Is there a way for a gem to bring its own tab completion?
While you are typing the command to start your script, your script isn’t running yet. It can’t intervene in the processing of its own arguments while they are still being typed. If possible, you can have the
gemfile install a bash completion file and modify the user’s~/.bashrcfile to load them as part of the installation process.