distrobox icon indicating copy to clipboard operation
distrobox copied to clipboard

[Error] Zsh completions not auto-completing container names

Open UncleGravity opened this issue 1 year ago • 1 comments

Describe the bug Running distrobox-enter <TAB> doesn't show the correct completion in zsh. It works correctly in bash. I think the zsh completions have a bug so I fixed it in my local machine and now completions work correctly. I don't know if this is a "shippable" fix but I wanted to share here.

#compdef distrobox-enter

_distrobox_containers() {
  local -a containers
  containers=(${(f)"$(distrobox list --no-color | tail -n +2 | cut -d'|' -f2 | tr -d ' ')"})
  _describe 'container name' containers
}

_arguments \
  '(--name -n)'{-n,--name}'[name for the distrobox]:container name:_distrobox_containers' \
  '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \
  '(--help -h)'{-h,--help}'[show this message]' \
  '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \
  '(--version -V)'{-V,--version}'[show version]' \
  '*:container name:_distrobox_containers'

same for distrobox-rm

#compdef distrobox-rm

_distrobox_containers() {
  local -a containers
  containers=(${(f)"$(distrobox list --no-color | tail -n +2 | cut -d'|' -f2 | tr -d ' ')"})
  _describe 'container name' containers
}

_arguments \
  '(--all -a)'{-a,--all}'[delete all distroboxes]' \
  '(--force -f)'{-f,--force}'[force deletion]' \
  '--rm-home[remove the mounted home if it differs from the host users one]' \
  '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \
  '(--help -h)'{-h,--help}'[show this message]' \
  '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \
  '(--version -V)'{-V,--version}'[show version]' \
  '*:container name:_distrobox_containers'

The same issue in distrobox-stop, upgrade, etc.

To Reproduce

  1. Create new container
  2. In zsh, run distrobox-enter <TAB>

Expected behavior Expecting a list of available containers. But it returns a list of files in the local directory.

Desktop (please complete the following information):

  • Are you using podman, docker or lilipod? Podman v5.1.1

  • Which version of distrobox? distrobox v1.7.2.1

  • Which host distribution? NixOS

  • How did you install distrobox? NixOS home-manager

UncleGravity avatar Jul 12 '24 02:07 UncleGravity

@fredricocalamari can help here? He did the zsh stuff :)

89luca89 avatar Oct 12 '24 10:10 89luca89

@fredricocalamari can help here? He did the zsh stuff :)

I'm here. I'll take a look into it. I have different dynamic completions for distrobox that I created about 8 months ago here: https://github.com/fredricocalamari/zsh-completions/tree/master/distrobox

After experimenting with dynamic completions, I tried submitting a merge request, but I encountered some unexpected issues that I found after submitting it for review. I rewrote them with different logic, a few times, and ended up with the ones linked above. I am sure they mostly solid, although I don't have people to test them.

fredricocalamari avatar Oct 24 '24 02:10 fredricocalamari

Describe the bug Running distrobox-enter <TAB> doesn't show the correct completion in zsh. It works correctly in bash. I think the zsh completions have a bug so I fixed it in my local machine and now completions work correctly. I don't know if this is a "shippable" fix but I wanted to share here.

#compdef distrobox-enter

_distrobox_containers() {
  local -a containers
  containers=(${(f)"$(distrobox list --no-color | tail -n +2 | cut -d'|' -f2 | tr -d ' ')"})
  _describe 'container name' containers
}

_arguments \
  '(--name -n)'{-n,--name}'[name for the distrobox]:container name:_distrobox_containers' \
  '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \
  '(--help -h)'{-h,--help}'[show this message]' \
  '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \
  '(--version -V)'{-V,--version}'[show version]' \
  '*:container name:_distrobox_containers'

same for distrobox-rm

#compdef distrobox-rm

_distrobox_containers() {
  local -a containers
  containers=(${(f)"$(distrobox list --no-color | tail -n +2 | cut -d'|' -f2 | tr -d ' ')"})
  _describe 'container name' containers
}

_arguments \
  '(--all -a)'{-a,--all}'[delete all distroboxes]' \
  '(--force -f)'{-f,--force}'[force deletion]' \
  '--rm-home[remove the mounted home if it differs from the host users one]' \
  '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \
  '(--help -h)'{-h,--help}'[show this message]' \
  '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \
  '(--version -V)'{-V,--version}'[show version]' \
  '*:container name:_distrobox_containers'

The same issue in distrobox-stop, upgrade, etc.

To Reproduce

1. Create new container

2. In zsh, run `distrobox-enter <TAB>`

Expected behavior Expecting a list of available containers. But it returns a list of files in the local directory.

Desktop (please complete the following information):

* Are you using podman, docker or lilipod?
  Podman v5.1.1

* Which version of distrobox?
  distrobox v1.7.2.1

* Which host distribution?
  NixOS

* How did you install distrobox?
  NixOS home-manager

Can you try these completions to see if these work better for you? Test them thoroughly and let me know if there's any problems. https://github.com/fredricocalamari/zsh-completions/tree/master/distrobox

fredricocalamari avatar Oct 24 '24 02:10 fredricocalamari

Fixed in #1603

fredricocalamari avatar Nov 05 '24 09:11 fredricocalamari

Fixed thanks to @fredricocalamari

89luca89 avatar Jan 19 '25 09:01 89luca89