mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-12-04 20:25:01 -05:00
In order to prevent bloating the shell with thousands of bash completion specs, bash completions are lazy-loaded as soon as the command is first tab-completed. This only works when the completionsdir contains a filename with the same name as the command being completed; as a result, calibre commands were able to be tab-completed only after 'calibre' was first completed. (This is unlike the zsh completions, which work when installed as a single unified file because zsh builds a cache of all known compdefs, and can load a completion on demand by reading from the file which contains it.) One common solution for programs which install several completions that share common helper functions is to install the completions in one file, and symlink all other command names to ensure the file is loaded by any name. I've opted for the other solution, which is to install each completion separately, since there is no common helper function to load once and use everywhere. As a result, there are some small speedups to be gained from only loading the completions being used. The main change is reindenting a lot of code to no longer be in a global context manager, but instead get written inside o_and_e/o_and_w. It's also necessary to write each individual completion file to the uninstaller, so do that.