Skip to content

completion: fix zsh __docker_plugins bad math expression - #7250

Open
FrancescoCastaldi wants to merge 1 commit into
docker:masterfrom
FrancescoCastaldi:fix/2761-zsh-plugins-completion
Open

completion: fix zsh __docker_plugins bad math expression#7250
FrancescoCastaldi wants to merge 1 commit into
docker:masterfrom
FrancescoCastaldi:fix/2761-zsh-plugins-completion

Conversation

@FrancescoCastaldi

Copy link
Copy Markdown

The \TAG\ column no longer exists in \docker plugin ls\ output. When the __docker_plugins\ function tried to extract the non-existent \TAG\ column, the header parser returned an empty string for \�egin[TAG]\ and \end[TAG], which evaluated to \

The TAG column no longer exists in 'docker plugin ls' output.
When the function tried to extract the non-existent TAG column,
it received an empty string, which caused a 'bad math expression'
error in zsh.

Fix by reading the ID column instead, and correct the padding
direction from l: (left-pad) to r: (right-truncate) so that IDs
are correctly shortened to 7 characters from the right.

Fixes docker#2761
Comment on lines 1576 to +1578
for line in $lines; do
s="${line[${begin[NAME]},${end[NAME]}]%% ##}"
s="$s:${(l:7:: :::)${${line[${begin[TAG]},${end[TAG]}]}%% ##}}"
s="$s:${(r:7:: :::)${${line[${begin[ID]},${end[ID]}]}%% ##}}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps instead, it should use --format to get the right fields, e.g.;

docker plugin ls --format='{{.ID}}\t{{.Name}}'
e91da965f5d9	vieux/sshfs:latest

FWIW; we mostly consider these hand-written completion script in "maintenance" mode, as the CLI now provide dynamically generated completion;

docker completion --help
Usage:  docker completion COMMAND

Generate the autocompletion script for docker for the specified shell.
See each sub-command's help for details on how to use the generated script.

Commands:
  bash        Generate the autocompletion script for bash
  fish        Generate the autocompletion script for fish
  powershell  Generate the autocompletion script for powershell
  zsh         Generate the autocompletion script for zsh

Run 'docker completion COMMAND --help' for more information on a command.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants