Skip to content

Instantly share code, notes, and snippets.

@davidmroth
Last active April 7, 2024 05:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmroth/fa26d433dd63ad799f7d384582e22ca4 to your computer and use it in GitHub Desktop.
Save davidmroth/fa26d433dd63ad799f7d384582e22ca4 to your computer and use it in GitHub Desktop.
Enabling `docker compose` alias, i.e., dc vs. docker compose
# Add to your .bashrc
# https://www.gnu.org/software/gnuastro/manual/html_node/Bash-TAB-completion-tutorial.html
if which docker >/dev/null 2>&1; then
__docker_compose_cmdline_completion() {
local commands cur prev words cword
COMPREPLY=()
_get_comp_words_by_ref -n : cur prev words cword
#echo -e "\nCUR=$cur PREV=$prev WORDS=$words CWORD=$cword\n"
[[ "$prev" == "$words" ]] && prev=''
commands=$( echo $(eval "/usr/libexec/docker/cli-plugins/docker-compose __completeNoDesc $prev '$2'" 2>/dev/null) )
commands=${commands%*:4}
IFS=$'\n' read -ra COMPREPLY -d '' < <(compgen -W "${commands[*]}" -- "$2")
return 0
}
complete -F __docker_compose_cmdline_completion dc # If you change the alias, you'll have to change it here too (dc)
alias dc="docker compose"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment