Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error] Zsh completions not auto-completing container names #1475

Closed
UncleGravity opened this issue Jul 12, 2024 · 5 comments
Closed

[Error] Zsh completions not auto-completing container names #1475

UncleGravity opened this issue Jul 12, 2024 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed wait-on-user waiting for a reply

Comments

@UncleGravity
Copy link

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 UncleGravity added the bug Something isn't working label Jul 12, 2024
@89luca89
Copy link
Owner

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

@89luca89 89luca89 added help wanted Extra attention is needed good first issue Good for newcomers wait-on-user waiting for a reply labels Oct 12, 2024
@fredricocalamari
Copy link
Contributor

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

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
Copy link
Contributor

Fixed in #1603

@89luca89
Copy link
Owner

Fixed thanks to @fredricocalamari

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed wait-on-user waiting for a reply
Projects
None yet
Development

No branches or pull requests

3 participants