Skip to content

Instantly share code, notes, and snippets.

Created April 9, 2017 05:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
HOWTO: autocompletion in a bash function/alias
# 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
# the __docker_complete_container_names function does something like the following
# COMPREPLY=( $(compgen -W "(list of containers)" -- "$cur") )
# documentaton :
# 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
# docker exec sh on the application
# complete adds autocompletion
# expects docker available in /etc/bash_completion.d
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