Skip to content

zsh completion breaks when optional arguments are combined (-i -t -> -it) #993

Open

Description

@kenden

BUG REPORT INFORMATION

Description

docker zsh completion breaks when optional arguments are combined.
Example, when -i and -t are combined to -it

This problem was reported here: ohmyzsh/ohmyzsh#6710

Steps to reproduce the issue:

  1. Make sure you are using zsh and check that the docker autocomplete is enabled.
    Type docker then press tab.
    If it shows you:
image   -- Manage images
images  -- List images

then docker zsh autocomplete is enabled.

  1. Type the following:
    docker run -it then press tab
    --> **PROBLEM: **A list of executables on the PATH is displayed instead of possible arguments to docker run

Describe the results you received:

When typing docker run -it and pressing tab, a list of executables on the PATH is displayed.

Describe the results you expected:

When typing docker run -it and pressing tab, I expect to get a list of possible arguments to docker run

Additional information you deem important (e.g. issue happens only occasionally):

When not combining options, it works fine. Ex, when typing
docker run -i -t and pressing tab, I get:

02f9d6707661  -- 18.04           in ubuntu
0458a4468cbc  -- xenial-20180123 in ubuntu
3fd9065eaf02  -- latest          in alpine
4ea294712533  -- latest          in nate/dockviz
5b117edd0b76  -- 12.04           in ubuntu

Output of docker version:

$ docker version
Client:
 Version:	18.03.0-ce
 API version:	1.37
 Go version:	go1.9.4
 Git commit:	0520e24
 Built:	Wed Mar 21 23:06:22 2018
 OS/Arch:	darwin/amd64
 Experimental:	false
 Orchestrator:	swarm

Server:
 Engine:
  Version:	18.03.0-ce
  API version:	1.37 (minimum version 1.12)
  Go version:	go1.9.4
  Git commit:	0520e24
  Built:	Wed Mar 21 23:14:32 2018
  OS/Arch:	linux/amd64
  Experimental:	true

I tried using the current lastest version available at https://github.com/docker/cli/blob/ec412bdbb47b0cd84d85a0212c7160cec0ee9f02/contrib/completion/zsh/_docker
(put the content of that file to ~/.oh-my-zsh/plugins/docker/_docker)
with the same result.

Output of docker info:

$ docker info
Containers: 8
 Running: 1
 Paused: 0
 Stopped: 7
Images: 16
Server Version: 18.03.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.87-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: QOY4:456J:JD4J:E36Y:G6FJ:YAJS:K3HI:J23J:NLV2:OFCV:ZNOY:STQT
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 31
 Goroutines: 56
 System Time: 2018-04-10T08:07:26.055313Z
 EventsListeners: 2
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

Using docker for mac.

Activity

  1. changed the title [-]https://github.com/robbyrussell/oh-my-zsh/issues/6710[/-] [+]docker completion breaks when optional arguments are combined (`-i -t` -> `-it`)[/+] on Apr 10, 2018
  2. changed the title [-]docker completion breaks when optional arguments are combined (`-i -t` -> `-it`)[/-] [+]zsh completion breaks when optional arguments are combined (`-i -t` -> `-it`)[/+] on Apr 10, 2018
  3. cpuguy83 commented on Apr 10, 2018

    @cpuguy83
    Collaborator

    Not reproing here:

     ✗ docker run -it
    -P  -- Publish all exposed ports
    -a  -- Attach to stdin, stdout or stderr
    -c  -- CPU shares (relative weight)
    -d  -- Detached mode: leave the container running in the background
    -e  -- Environment variables
    -h  -- Container host name
    -l  -- Container metadata
    -m  -- Memory limit
    -p  -- Expose a container's port to the host
    -u  -- Username or UID
    -v  -- Bind mount a volume
    -w  -- Working directory inside the container
    

    If I add a space after the -it, then attempt tab completion I see a list of all the images.
    Are we sure oh-my-zsh is up to date?

  4. thaJeztah commented on Apr 11, 2018

    @thaJeztah
    Member

    Perhaps related to the "short-stacking option", which is disabled by default;

    # Short-option stacking can be enabled with:
    # zstyle ':completion:*:*:docker:*' option-stacking yes
    # zstyle ':completion:*:*:docker-*:*' option-stacking yes

    See moby/moby#17124

  5. kenden commented on Apr 17, 2018

    @kenden
    Author

    @thaJeztah thanks, that's it. I uncommentted:

    #  zstyle ':completion:*:*:docker-*:*' option-stacking yes 
    

    on line

    # zstyle ':completion:*:*:docker-*:*' option-stacking yes

    and docker run -it now autocompletes as (I think) it should.

    The comment as to why this is disabled is here:
    moby/moby#17124 (comment)

  6. kenden commented on Apr 17, 2018

    @kenden
    Author

    Should we create an issue to enable autocomplete by default (or rename this issue for that)
    Between this, this, this and this it seems there is a demand for it.

  7. ratijas commented on Nov 27, 2020

    @ratijas

    Duplicate of, or rather duplicated by #2625.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions