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
@jocrau
Copy link

jocrau commented Mar 9, 2019

Worked. Thanks!!

@kokolingga
Copy link

It's works! Thank You.

@fzyzcjy
Copy link

fzyzcjy commented Mar 7, 2020

does not work for me...

@BastienRulat
Copy link

MAgic 😎👍

@iNoSec2
Copy link

iNoSec2 commented Feb 8, 2021

does not work for me...

same, adn that's weird because it worked on my previous laptop but the new one nope

@AratioD
Copy link

AratioD commented Feb 21, 2021

this works

@sayemarg
Copy link

Tnx You ❤️

@dbn000
Copy link

dbn000 commented Sep 2, 2022

Amazing... Thanks!

@ikilobyte
Copy link

Thank you ❤️

@xvv6u577
Copy link

xvv6u577 commented Jan 6, 2023

thx, perfectly worked!

@Timopheym
Copy link

thanks!

@BoscoDomingo
Copy link

Still working as of December 2023 <3

@rizzyDev
Copy link

Cool

@crazyoptimist
Copy link

I don't use oh-my-zsh. Below worked for me:

curl -fLo /usr/local/share/zsh/site-functions/_docker https://raw.githubusercontent.com/docker/cli/master/contrib/completion/zsh/_docker

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