@@ -94,27 +94,34 @@ Below are various examples of enabling ``shtab``'s own tab completion scripts.
9494bash
9595~~~~
9696
97+ .. code :: sh
98+
99+ shtab --shell=bash shtab.main.get_main_parser --error-unimportable \
100+ | sudo tee " $BASH_COMPLETION_COMPAT_DIR " /shtab
101+
102+ Eager bash
103+ ^^^^^^^^^^
104+
105+ If both `shtab ` and the module it's completing are globally importable, eager
106+ usage is an option. "Eager" means automatically updating completions each time a
107+ terminal is opened.
108+
97109.. code :: sh
98110
99111 # Install locally
100- echo ' which shtab && eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
112+ echo ' eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
101113 >> ~ /.bash_completion
102114
103115 # Install locally (lazy load for bash-completion>=2.8)
104- echo ' which shtab && eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
116+ echo ' eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
105117 > " ${BASH_COMPLETION_USER_DIR:- ${XDG_DATA_HOME:- $HOME / .local/ share} / bash-completion} /completions/shtab"
106118
107119 # Install system-wide
108- echo ' which shtab && eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
120+ echo ' eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
109121 | sudo tee " $( pkg-config --variable=completionsdir bash-completion) " /shtab
110122
111123 # Install system-wide (legacy)
112- echo ' which shtab && eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
113- | sudo tee " $BASH_COMPLETION_COMPAT_DIR " /shtab
114-
115- # Install once (will have to re-run if the target's CLI API changes,
116- # but doesn't need target to always be in $PYTHONPATH)
117- shtab --shell=bash shtab.main.get_main_parser --error-unimportable \
124+ echo ' eval "$(shtab --shell=bash shtab.main.get_main_parser)"' \
118125 | sudo tee " $BASH_COMPLETION_COMPAT_DIR " /shtab
119126
120127 zsh
@@ -125,20 +132,21 @@ Note that ``zsh`` requires completion script files to be named ``_{EXECUTABLE}``
125132
126133.. code :: sh
127134
128- # Install once (will have to re-run if the target's CLI API changes,
129- # but doesn't need target to always be in $PYTHONPATH)
135+ # note the underscore `_` prefix
130136 shtab --shell=zsh shtab.main.get_main_parser --error-unimportable \
131137 | sudo tee /usr/local/share/zsh/site-functions/_shtab
132138
139+ Eager zsh
140+ ^^^^^^^^^
141+
133142To be more eager, place the generated script somewhere in ``$fpath ``.
134143For example, add these lines to the top of ``~/.zshrc ``:
135144
136145.. code :: sh
137146
138147 mkdir -p ~ /.zsh/completions
139- fpath=($fpath ~ /.zsh/completions)
140- which shtab && shtab --shell=zsh shtab.main.get_main_parser \
141- > ~ /.zsh/completions/_shtab
148+ fpath=($fpath ~ /.zsh/completions) # must be before `compinit` lines
149+ shtab --shell=zsh shtab.main.get_main_parser > ~ /.zsh/completions/_shtab
142150
143151 Examples
144152--------
@@ -171,8 +179,8 @@ Assuming this code example is installed in ``MY_PROG.command.main``, simply run:
171179.. code :: sh
172180
173181 # bash
174- echo ' which shtab && eval "$(shtab --shell=bash MY_PROG.command.main.get_main_parser)" ' \
175- >> ~ /.bash_completion
182+ shtab --shell=bash -u MY_PROG.command.main.get_main_parser \
183+ | sudo tee " $BASH_COMPLETION_COMPAT_DIR " /MY_PROG
176184
177185 # zsh
178186 shtab --shell=zsh -u MY_PROG.command.main.get_main_parser \
@@ -191,7 +199,7 @@ in a different virtual environment, you'd have to add a line somewhere
191199appropriate (e.g. ``$CONDA_PREFIX/etc/conda/activate.d/env_vars.sh ``).
192200
193201By default, ``shtab `` will silently do nothing if it cannot import the requested
194- application. Use ``--error-unimportable `` to noisily complain.
202+ application. Use ``-u, - -error-unimportable `` to noisily complain.
195203
196204Advanced Configuration
197205----------------------
0 commit comments