Last active
March 16, 2022 12:24
-
-
Save jdkirkwood/36a0c3deff62765ef59d8c11477a5ca4 to your computer and use it in GitHub Desktop.
odev bash completion script
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
# odev tab completion script | |
# Version: 0.2 | |
# Install: Add a call to this script in ~/.bash_completion or copy the script into /etc/bash_completion.d/ | |
# 'source' the file to use the features in the current session. | |
# Call function 'odev_cache' to rebuild the cached list of databases. | |
# clear global cache | |
_odev_complete_list="" | |
odev_cache () | |
{ | |
_odev_complete_list="$( odev list | awk -v OFS=' ' 'NR > 3 { print $2 }' )" | |
} | |
_odev () # By convention, the function name | |
{ #+ starts with an underscore. | |
local cur prev words cword split opts | |
# initialise | |
_init_completion -s || return | |
case $COMP_CWORD in | |
1) | |
opts="clean cloc clone code create deploy dump export get help init kill list pull quickstart rebuild remove rename restore run scaffold set sh test upgrade upgrade-build upgrade-manual upgrade-merge upgrade-wait upload version" | |
;; | |
2) | |
if [ -z "$_odev_complete_list" ]; then | |
odev_cache | |
fi | |
opts=${_odev_complete_list} | |
;; | |
*) | |
_filedir | |
return | |
esac | |
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | |
return | |
} && | |
complete -F _odev -o filenames odev | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment