-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: easier tab completion activation:
source tab-qiime
(#84)
Removes the ugly and hard-to-remember `eval "$(register-qiime-completion 2> /dev/null)"` command in favor of `source tab-qiime`. Also enables tab completion out of the box for a fresh q2cli install once users run this command. Thanks @thermokarst and @gregcaporaso for your input!
- Loading branch information
1 parent
d0bf53b
commit aad9d67
Showing
6 changed files
with
58 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Bash completion script that defers to a cached completion script representing | ||
# the state of the current QIIME 2 deployment. | ||
# | ||
# This script is intended to be executed on the command-line or in | ||
# .bashrc/.bash_profile: | ||
# | ||
# source tab-qiime | ||
# | ||
|
||
_qiime_completion() | ||
{ | ||
# Attempt to find the cached completion script. If q2cli isn't installed, or | ||
# is an incompatible version, don't attempt completion. | ||
local path="$(python -c "import q2cli.util; print(q2cli.util.get_completion_path())" 2> /dev/null)" | ||
|
||
if [[ $? != 0 ]]; then | ||
unset COMPREPLY | ||
return 0 | ||
fi | ||
|
||
# If the completion script exists, attempt completion by invoking the script | ||
# in a subshell, supplying COMP_WORDS and COMP_CWORD. Capture the output as | ||
# the completion reply. If the completion script failed, don't attempt | ||
# completion. | ||
if [[ -f "$path" ]] ; then | ||
COMPREPLY=( $(COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD="${COMP_CWORD}" "$path" 2> /dev/null) ) | ||
|
||
if [[ $? != 0 ]]; then | ||
unset COMPREPLY | ||
return 0 | ||
fi | ||
else | ||
unset COMPREPLY | ||
return 0 | ||
fi | ||
|
||
return 0 | ||
} | ||
|
||
# Enable default readline and bash completion behavior when `_qiime_completion` | ||
# doesn't have a reply. | ||
complete -F _qiime_completion -o default -o bashdefault qiime | ||
|
||
# Execute a `qiime` command (any command will do) so that tab-completion will | ||
# work out-of-the-box (e.g. with a fresh installation of q2cli). Running a | ||
# command will create or refresh the cache if necessary, which contains the | ||
# actual completion script. | ||
# | ||
# Ignore stdout to avoid displaying help text to users enabling tab-completion. | ||
# stderr displays the note about cache refreshing, as that can take a few | ||
# moments to complete. | ||
qiime > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters