Skip to content

Instantly share code, notes, and snippets.

@ro31337
Created August 13, 2017 02:12
Show Gist options
  • Save ro31337/b2c33ad0b90636e9e3bb76fb4fb76907 to your computer and use it in GitHub Desktop.
Save ro31337/b2c33ad0b90636e9e3bb76fb4fb76907 to your computer and use it in GitHub Desktop.
Zsh docker completion

Docker Completion for Zsh (Official)

  • mkdir -p ~/.oh-my-zsh/plugins/docker/
  • curl -fLo ~/.oh-my-zsh/plugins/docker/_docker https://raw.githubusercontent.com/docker/cli/master/contrib/completion/zsh/_docker
  • Add docker to plugins section in ~/.zshrc
  • exec zsh
@bistoco
Copy link

bistoco commented Apr 19, 2025

First of all, thanks. I want it to add the plugin in one command, so this one adds it to the end of the list.
sed -i 's/\(^plugins=(.*\)\()$\)/\1 docker\2/' ~/.zshrc
Longer explanation

# ADD THE PLUGIN TO ~/.zshrc IN THE PLUGINS SECTION
# - ADD AT THE START OF LIST (AFTER THE OPEN PARENTHESIS)
#   sed -i 's/plugins=(/plugins=(docker /' ~/.zshrc
# - ADD AT THE END OF THE LIST VERSION (BEFORE CLOSING PARENTHESIS)
sed -i 's/\(^plugins=(.*\)\()$\)/\1 docker\2/' ~/.zshrc
# 's/               > Default sed substitution start
# \(^plugins=(.*\)  > Captures as $1, in a line starting with 'plugins=(', everything BEFORE the closing ')'
# \()$\)            > Captures as $2, the closing ')'
# /\1 docker\2/'    > Replaces the whole line with $1 + ' docker' + $2
# FOR EXAMPLE, AN ORIGINAL LINE IN ~/.zshrc > "plugins=(git)"
# APPLYING THE SED COMMAND  >
#   $1:  'plugins=(git'
#   Add: ' docker'
#   $2:  ')'
# RESULT > 'plugins=(git docker)'
# TO TEST WITHOUT SUBSTITUTION
#   sed 's/\(^plugins=(.*\)\()$\)/\1 docker\2/' ~/.zshrc | grep -E '^plugins='
# EXPLANATION FOR SED'S PARTS FROM https://stackoverflow.com/a/14137448/30293736

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment