HOWTO: autocompletion in a bash function/alias
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
# I have a function called as shocker which 'sh-es' into a docker container | |
# to enable autocompletion in the command, I do the following | |
# `complete -F __docker_complete_container_names shocker` | |
# __docker_complete_container_names is a function available in /etc/bash_completion.d/docker | |
# the above file is available at https://docs.docker.com/machine/completion/ | |
# the __docker_complete_container_names function does something like the following | |
# COMPREPLY=( $(compgen -W "(list of containers)" -- "$cur") ) | |
# documentaton : http://www.tldp.org/LDP/abs/html/tabexpansion.html | |
# WHERE : $cur is the current value of the cursor that should be autocompleted | |
# | |
# To check the function already available on your terminal, run the command | |
# `typeset -F` - i'd grep it with what i want | |
# `typeset -F | grep -i git` | |
# NOTE : These are all functions available, all of they may not be for autocompletion | |
# For git: check https://github.com/git/git/blob/master/contrib/completion/git-completion.bash | |
# | |
# docker exec sh on the application | |
# | |
# complete adds autocompletion | |
# expects docker available in /etc/bash_completion.d | |
# https://docs.docker.com/machine/completion/ | |
complete -F __docker_complete_container_names shocker | |
shocker() { | |
docker exec -it $1 sh | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment