From 3848ac9b11908c96b1f0eb1103200922adf8894d Mon Sep 17 00:00:00 2001 From: Fredrico Calamari Date: Tue, 5 Nov 2024 02:10:34 -0700 Subject: [PATCH] zsh completions reworked. fixed not completing container names. --- completions/zsh/_distrobox | 1 - completions/zsh/_distrobox-assemble | 1 + completions/zsh/_distrobox-create | 71 +++++++++++------- completions/zsh/_distrobox-enter | 44 +++++++++--- completions/zsh/_distrobox-ephemeral | 72 +++++++++++-------- completions/zsh/_distrobox-export | 5 +- completions/zsh/_distrobox-generate-entry | 42 ++++++++--- completions/zsh/_distrobox-host-exec | 11 +-- completions/zsh/_distrobox-init | 1 + completions/zsh/_distrobox-list | 1 + completions/zsh/_distrobox-rm | 43 ++++++++--- completions/zsh/_distrobox-stop | 38 +++++++--- completions/zsh/_distrobox-upgrade | 37 +++++++--- completions/zsh/_distrobox_containers | 7 ++ completions/zsh/_distrobox_images | 7 ++ completions/zsh/_distrobox_running_containers | 9 +++ 16 files changed, 279 insertions(+), 111 deletions(-) mode change 100755 => 100644 completions/zsh/_distrobox mode change 100755 => 100644 completions/zsh/_distrobox-assemble mode change 100755 => 100644 completions/zsh/_distrobox-create mode change 100755 => 100644 completions/zsh/_distrobox-enter mode change 100755 => 100644 completions/zsh/_distrobox-ephemeral mode change 100755 => 100644 completions/zsh/_distrobox-export mode change 100755 => 100644 completions/zsh/_distrobox-generate-entry mode change 100755 => 100644 completions/zsh/_distrobox-host-exec mode change 100755 => 100644 completions/zsh/_distrobox-init mode change 100755 => 100644 completions/zsh/_distrobox-list mode change 100755 => 100644 completions/zsh/_distrobox-rm mode change 100755 => 100644 completions/zsh/_distrobox-stop mode change 100755 => 100644 completions/zsh/_distrobox-upgrade create mode 100644 completions/zsh/_distrobox_containers create mode 100644 completions/zsh/_distrobox_images create mode 100644 completions/zsh/_distrobox_running_containers diff --git a/completions/zsh/_distrobox b/completions/zsh/_distrobox old mode 100755 new mode 100644 index f64642f788..05dd1cf802 --- a/completions/zsh/_distrobox +++ b/completions/zsh/_distrobox @@ -60,4 +60,3 @@ case $state in ;; esac esac - diff --git a/completions/zsh/_distrobox-assemble b/completions/zsh/_distrobox-assemble old mode 100755 new mode 100644 index 92db72fd5f..3822f5b244 --- a/completions/zsh/_distrobox-assemble +++ b/completions/zsh/_distrobox-assemble @@ -1,5 +1,6 @@ #compdef distrobox-assemble +_message -r "Create or remove containers in batches, based on a manifest file." _arguments \ '1:command:(create rm)' \ '--file[path to the distrobox manifest/ini file]:file:_files' \ diff --git a/completions/zsh/_distrobox-create b/completions/zsh/_distrobox-create old mode 100755 new mode 100644 index fac0eefa54..5ff764d53c --- a/completions/zsh/_distrobox-create +++ b/completions/zsh/_distrobox-create @@ -1,29 +1,46 @@ #compdef distrobox-create -_arguments -s \ - '(--image -i)'{-i,--image}'[image to use for the container]:image:_files' \ - '(--name -n)'{-n,--name}'[name for the distrobox]:name:' \ - '(--pull -p)'{-p,--pull}'[pull the image even if it exists locally (implies --yes)]' \ - '(--yes -Y)'{-Y,--yes}'[non-interactive, pull images without asking]' \ - '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \ - '(--clone -c)'{-c,--clone}'[name of the distrobox container to use as base for a new container]:clone container name:' \ - '(--home -H)'{-H,--home}'[select a custom HOME directory for the container]:path:_files -/' \ - '--volume[additional volumes to add to the container]:volume:_files' \ - '(--additional-flags -a)'{-a,--additional-flags}'[additional flags to pass to the container manager command]:flags:' \ - '(--additional-packages -ap)'{-ap,--additional-packages}'[additional packages to install during initial container setup]:package:' \ - '--init-hooks[additional commands to execute during container initialization]:command:' \ - '--pre-init-hooks[additional commands to execute prior to container initialization]:command:' \ - '(--init -I)'{-I,--init}'[use init system inside the container]' \ - '--nvidia[try to integrate host nVidia drivers in the guest]' \ - '--unshare-devsys[do not share host devices and sysfs dirs from host]' \ - '--unshare-ipc[do not share ipc namespace with host]' \ - '--unshare-netns[do not share the net namespace with host]' \ - '--unshare-process[do not share process namespace with host]' \ - '--unshare-all[activate all the unshare flags]' \ - '(--compatibility -C)'{-C,--compatibility}'[show list of compatible images]' \ - '(--help -h)'{-h,--help}'[show this message]' \ - '--no-entry[do not generate a container entry in the application list]' \ - '(--dry-run -d)'{-d,--dry-run}'[only print the container manager command generated]' \ - '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ - '(--version -V)'{-V,--version}'[show version]' \ - '--absolutely-disable-root-password-i-am-really-positively-sure[skip user password setup, leaving it blank]' +_distrobox-create() { + local -a options + local expl + local state + # Array of optargs to pass to _arguments for matching and completion + options=( + '(-i --image)'{-i,--image}'[Specify image to use for the container]:image:_distrobox_images' + '(-n --name)'{-n,--name}'[Specify name for the distrobox]:distrobox name:' + '--hostname[Specify hostname for the distrobox]:hostname:' + '(-p --pull)'{-p,--pull}'[Pull the image even if it exists locally (implies --yes)]' + '(-Y --yes)'{-Y,--yes}'[Non-interactive, pull images without asking]' + '(-r --root)'{-r,--root}'[Launch with root privileges using podman/docker/lilipod]' + '(-c --clone)'{-c,--clone}'[Name of the distrobox container to use as base for a new container]:clone container name:' + '(-H --home)'{-H,--home}'[Select a custom HOME directory for the container]:path:_files -/' + '--volume[Add additional volumes to the container]:volume:_files' + '(-a --additional-flags)'{-a,--additional-flags}'[Additional flags to pass to the container manager command]:flags:' + '(-ap --additional-packages)'{-ap,--additional-packages}'[Additional packages to install during setup]:package:' + '--init-hooks[Commands to execute during container initialization]:command:' + '--pre-init-hooks[Commands to execute prior to container initialization]:command:' + '(-I --init)'{-I,--init}'[Use an init system inside the container]' + '--nvidia[Try to integrate host nVidia drivers into the guest]' + '--unshare-devsys[Do not share host devices and sysfs dirs from host]' + '--unshare-groups[Do not forward users additional groups into the container]' + '--unshare-ipc[Do not share ipc namespace with host]' + '--unshare-netns[Do not share the net namespace with host]' + '--unshare-process[Do not share process namespace with host]' + '--unshare-all[Activate all the unshare flags]' + '(-C --compatibility)'{-C,--compatibility}'[Show list of compatible images]' + '(-h --help)'{-h,--help}'[Show this message]' + '--no-entry[Do not generate a container entry in the application list]' + '(-d --dry-run)'{-d,--dry-run}'[Only print the container manager command generated]' + '(-v --verbose)'{-v,--verbose}'[Show more verbosity]' + '(-V --version)'{-V,--version}'[Show version]' + '--absolutely-disable-root-password-i-am-really-positively-sure[Skip user password setup, leaving it blank]' + ) + # Simple logic + _message -r "Create new distroboxes." + _arguments \ + '1:containers:->container' \ + '*:options:->options' \ + $options[@] +} + +_distrobox-create diff --git a/completions/zsh/_distrobox-enter b/completions/zsh/_distrobox-enter old mode 100755 new mode 100644 index b37dea9de1..d16e9a990e --- a/completions/zsh/_distrobox-enter +++ b/completions/zsh/_distrobox-enter @@ -1,13 +1,35 @@ #compdef distrobox-enter -_arguments -s \ - '(--name -n)'{-n,--name}'[name for the distrobox]:distrobox name:' \ - '--[end arguments and execute the rest as command to execute at login]:command:_command_names' \ - '(--no-tty -T)'{-T,--no-tty}'[do not instantiate a tty]' \ - '(--no-workdir -nw)'{-nw,--no-workdir}'[always start the container from container home directory]' \ - '(--additional-flags -a)'{-a,--additional-flags}'[additional flags to pass to the container manager command]:flags:' \ - '(--help -h)'{-h,--help}'[show this message]' \ - '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \ - '(--dry-run -d)'{-d,--dry-run}'[only print the container manager command generated]' \ - '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ - '(--version -V)'{-V,--version}'[show version]' +_distrobox-enter() { + local -a options + local expl + local state + local _db_cc + + _db_cc=("${(@f)$(distrobox list | sed 1d | awk -F'|' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')}") + + options=( + '(--name -n)'{-n,--name}'[name for the distrobox]:container:_distrobox_containers' + '--[end arguments and execute the rest as command to execute at login]:command:_command_names' + '(--no-tty -T)'{-T,--no-tty}'[do not instantiate a tty]' + '(--no-workdir -nw)'{-nw,--no-workdir}'[always start the container from container home directory]' + '(--additional-flags -a)'{-a,--additional-flags}'[additional flags to pass to the container manager command]:flags:' + '(--help -h)'{-h,--help}'[show this message]' + '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' + '(--dry-run -d)'{-d,--dry-run}'[only print the container manager command generated]' + '(--verbose -v)'{-v,--verbose}'[show more verbosity]' + '(--version -V)'{-V,--version}'[show version]' + ) + _message -r "Start and enter a distrobox." + if [[ -n "$_db_cc" ]]; then + _arguments -C \ + '1:containers:_distrobox_containers' \ + $options[@] + else + _message -r "No containers exist." + _arguments $options[@] + fi + +} + +_distrobox-enter diff --git a/completions/zsh/_distrobox-ephemeral b/completions/zsh/_distrobox-ephemeral old mode 100755 new mode 100644 index 08306e9a27..9c91a24493 --- a/completions/zsh/_distrobox-ephemeral +++ b/completions/zsh/_distrobox-ephemeral @@ -1,30 +1,46 @@ #compdef distrobox-ephemeral -_arguments -s \ - '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \ - '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ - '(--help -h)'{-h,--help}'[show this message]' \ - '--[end arguments and execute the rest as command to execute at login]:command:_command_names' \ - '(--version -V)'{-V,--version}'[show version]' \ - '(--image -i)'{-i,--image}'[image to use for the container]:image:_files' \ - '(--name -n)'{-n,--name}'[name for the distrobox]:name:' \ - '(--pull -p)'{-p,--pull}'[pull the image even if it exists locally (implies --yes)]' \ - '(--yes -Y)'{-Y,--yes}'[non-interactive, pull images without asking]' \ - '(--clone -c)'{-c,--clone}'[name of the distrobox container to use as base for a new container]:clone container name:' \ - '(--home -H)'{-H,--home}'[select a custom HOME directory for the container]:path:_files -/' \ - '--volume[additional volumes to add to the container]:volume:_files' \ - '(--additional-flags -a)'{-a,--additional-flags}'[additional flags to pass to the container manager command]:flags:' \ - '(--additional-packages -ap)'{-ap,--additional-packages}'[additional packages to install during initial container setup]:package:' \ - '--init-hooks[additional commands to execute during container initialization]:command:' \ - '--pre-init-hooks[additional commands to execute prior to container initialization]:command:' \ - '(--init -I)'{-I,--init}'[use init system inside the container]' \ - '--nvidia[try to integrate hosts nVidia drivers in the guest]' \ - '--unshare-devsys[do not share host devices and sysfs dirs from host]' \ - '--unshare-ipc[do not share ipc namespace with host]' \ - '--unshare-netns[do not share the net namespace with host]' \ - '--unshare-process[do not share process namespace with host]' \ - '--unshare-all[activate all the unshare flags]' \ - '(--compatibility -C)'{-C,--compatibility}'[show list of compatible images]' \ - '--no-entry[do not generate a container entry in the application list]' \ - '(--dry-run -d)'{-d,--dry-run}'[only print the container manager command generated]' \ - '--absolutely-disable-root-password-i-am-really-positively-sure[skip user password setup, leaving it blank]' +_distrobox-ephemeral() { + local -a options + local expl + local state + # Array of optargs to pass to _arguments for matching and completion + options=( + '(-i --image)'{-i,--image}'[Specify image to use for the container]:image:_distrobox_images' + '(-n --name)'{-n,--name}'[Specify name for the distrobox]:distrobox name:' + '--hostname[Specify hostname for the distrobox]:hostname:' + '(-p --pull)'{-p,--pull}'[Pull the image even if it exists locally (implies --yes)]' + '(-Y --yes)'{-Y,--yes}'[Non-interactive, pull images without asking]' + '(-r --root)'{-r,--root}'[Launch with root privileges using podman/docker/lilipod]' + '(-c --clone)'{-c,--clone}'[Name of the distrobox container to use as base for a new container]:clone container name:' + '(-H --home)'{-H,--home}'[Select a custom HOME directory for the container]:path:_files -/' + '--volume[Add additional volumes to the container]:volume:_files' + '(-a --additional-flags)'{-a,--additional-flags}'[Additional flags to pass to the container manager command]:flags:' + '(-ap --additional-packages)'{-ap,--additional-packages}'[Additional packages to install during setup]:package:' + '--init-hooks[Commands to execute during container initialization]:command:' + '--pre-init-hooks[Commands to execute prior to container initialization]:command:' + '(-I --init)'{-I,--init}'[Use an init system inside the container]' + '--nvidia[Try to integrate host nVidia drivers into the guest]' + '--unshare-devsys[Do not share host devices and sysfs dirs from host]' + '--unshare-groups[Do not forward users additional groups into the container]' + '--unshare-ipc[Do not share ipc namespace with host]' + '--unshare-netns[Do not share the net namespace with host]' + '--unshare-process[Do not share process namespace with host]' + '--unshare-all[Activate all the unshare flags]' + '(-C --compatibility)'{-C,--compatibility}'[Show list of compatible images]' + '(-h --help)'{-h,--help}'[Show this message]' + '--no-entry[Do not generate a container entry in the application list]' + '(-d --dry-run)'{-d,--dry-run}'[Only print the container manager command generated]' + '(-v --verbose)'{-v,--verbose}'[Show more verbosity]' + '(-V --version)'{-V,--version}'[Show version]' + '--absolutely-disable-root-password-i-am-really-positively-sure[Skip user password setup, leaving it blank]' + ) + # Simple logic + _message -r "Create temporary distroboxes that are auto destroyed." + _arguments \ + '1:containers:->container' \ + '*:options:->options' \ + $options[@] +} + +_distrobox-ephemeral diff --git a/completions/zsh/_distrobox-export b/completions/zsh/_distrobox-export old mode 100755 new mode 100644 index 7fd2ca2c79..135e99180f --- a/completions/zsh/_distrobox-export +++ b/completions/zsh/_distrobox-export @@ -1,6 +1,7 @@ #compdef distrobox-export -_arguments -s \ +_message -r "Export an app or a binary from the container to the host." +_arguments \ '(--app -a)'{-a,--app}'[name of the application to export]:application name:' \ '(--bin -b)'{-b,--bin}'[absolute path of the binary to export]:path to binary:_files' \ '(--delete -d)'{-d,--delete}'[delete exported application or binary]' \ @@ -8,6 +9,8 @@ _arguments -s \ '(--export-path -ep)'{-ep,--export-path}'[path where to export the binary]:export path:_files' \ '(--extra-flags -ef)'{-ef,--extra-flags}'[extra flags to add to the command]:extra flags:' \ '(--enter-flags -nf)'{-nf,--enter-flags}'[flags to add to distrobox-enter]:enter flags:' \ + '--list-apps[list applications exported from this container]' \ + '--list-binaries[list binaries exported from this container, use -ep to specify custom paths to search]' \ '(--sudo -S)'{-S,--sudo}'[specify if the exported item should be run as sudo]' \ '(--help -h)'{-h,--help}'[show this message]' \ '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ diff --git a/completions/zsh/_distrobox-generate-entry b/completions/zsh/_distrobox-generate-entry old mode 100755 new mode 100644 index ff2a91b4bf..a9fd1ca64d --- a/completions/zsh/_distrobox-generate-entry +++ b/completions/zsh/_distrobox-generate-entry @@ -1,11 +1,35 @@ #compdef distrobox-generate-entry -_arguments -s \ - ':container name:_files' \ - '(--help -h)'{-h,--help}'[show this message]' \ - '(--all -a)'{-a,--all}'[perform for all distroboxes]' \ - '(--delete -d)'{-d,--delete}'[delete the entry]' \ - '(--icon -i)'{-i,--icon}'[specify a custom icon (default auto)]:icon path:_files' \ - '(--root -r)'{-r,--root}'[perform on rootful distroboxes]' \ - '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ - '(--version -V)'{-V,--version}'[show version]' +_distrobox-generate-entry() { + # expl is an internal zsh array that gets passed to _arguments bts + local expl + local -a options + local _db_cc + # Check for existing containers and store the result into var _db_cc + _db_cc=("${(@f)$(distrobox list | sed 1d | awk -F'|' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')}") + # Array of optargs to pass to _arguments for matching and completion + options=( + '(-h --help)'{-h,--help}'[show this message]' + '(-a --all)'{-a,--all}'[perform for all distroboxes]' + '(-d --delete)'{-d,--delete}'[delete the entry]' + '(-i --icon)'{-i,--icon}'[specify a custom icon (default auto)]:icon path:(auto _files)' + '(-r --root)'{-r,--root}'[perform on rootful distroboxes]' + '(-v --verbose)'{-v,--verbose}'[show more verbosity]' + '(-V --version)'{-V,--version}'[show version]' + ) + _message -r "Create a desktop icon for a distrobox" + # If containers exist then do an action + if [[ -n "$_db_cc" ]]; then + # Match both container names and optargs + _arguments \ + '*:containers:_distrobox_containers' \ + $options[@] + # If no containers exist then do an action + else + # Display message to user and match optargs only + _message -r "No containers exist." + _arguments $options[@] + fi +} + +_distrobox-generate-entry diff --git a/completions/zsh/_distrobox-host-exec b/completions/zsh/_distrobox-host-exec old mode 100755 new mode 100644 index a9731cecce..3333fa4860 --- a/completions/zsh/_distrobox-host-exec +++ b/completions/zsh/_distrobox-host-exec @@ -1,14 +1,9 @@ #compdef distrobox-host-exec +_message -r "Execute a command on the host while in a container" _arguments \ + '*:command:_command' \ '(--help -h)'{-h,--help}'[show this message]' \ '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ '(--version -V)'{-V,--version}'[show version]' \ - '(--yes -Y)'{-Y,--yes}'[Automatically answer yes to prompt host-spawn will be installed on the guest system if not detected]' \ - '*:command:->command' - -case $state in - command) - _command - ;; -esac + '(--yes -Y)'{-Y,--yes}'[Automatically answer yes to prompt host-spawn will be installed on the guest system if not detected]' diff --git a/completions/zsh/_distrobox-init b/completions/zsh/_distrobox-init old mode 100755 new mode 100644 index 5d6c3ef3fc..e79a3fca56 --- a/completions/zsh/_distrobox-init +++ b/completions/zsh/_distrobox-init @@ -1,5 +1,6 @@ #compdef distrobox-init +_message -r "Init the distrobox (not to be launched manually)" _arguments \ '(--name -n)'{-n,--name}'[user name]:user name:' \ '(--user -u)'{-u,--user}'[uid of the user]:uid:' \ diff --git a/completions/zsh/_distrobox-list b/completions/zsh/_distrobox-list old mode 100755 new mode 100644 index 9e72567b3b..2ad1939b5f --- a/completions/zsh/_distrobox-list +++ b/completions/zsh/_distrobox-list @@ -1,5 +1,6 @@ #compdef distrobox-list +_message -r "List available distroboxes." _arguments \ '(--help -h)'{-h,--help}'[show this message]' \ '--no-color[disable color formatting]' \ diff --git a/completions/zsh/_distrobox-rm b/completions/zsh/_distrobox-rm old mode 100755 new mode 100644 index 2f52120ab5..3b0ddb4d9e --- a/completions/zsh/_distrobox-rm +++ b/completions/zsh/_distrobox-rm @@ -1,11 +1,36 @@ #compdef distrobox-rm -_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:_files' +_distrobox-rm() { + # expl is an internal zsh array that gets passed to _arguments bts + local expl + local -a options + local _db_cc + # Check for existing containers and store the result into var _db_cc + _db_cc=("${(@f)$(distrobox list | sed 1d | awk -F'|' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')}") + # Array of optargs to pass to _arguments for matching and completion + options=( + '(-a --all)'{-a,--all}'[delete all distroboxes]' + '(-f --force)'{-f,--force}'[force deletion]' + '--rm-home[remove the mounted home if it differs from the host users one]' + '(-r --root)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' + '(-h --help)'{-h,--help}'[show this message]' + '(-v --verbose)'{-v,--verbose}'[show more verbosity]' + '(-V --version)'{-V,--version}'[show version]' + ) + _message -r "Delete one or more distroboxes." + # If containers exist then do an action + if [[ -n "$_db_cc" ]]; then + # Match both container names and optargs + _arguments \ + '*:containers:_distrobox_containers' \ + $options[@] + # If no containers exist then do an action + else + # Display message to user and match optargs only + _message -r "No containers exist." + _arguments $options[@] + fi + +} + +_distrobox-rm diff --git a/completions/zsh/_distrobox-stop b/completions/zsh/_distrobox-stop old mode 100755 new mode 100644 index 804ec13810..9ceccbd202 --- a/completions/zsh/_distrobox-stop +++ b/completions/zsh/_distrobox-stop @@ -1,11 +1,31 @@ #compdef distrobox-stop -_arguments \ - '--name[specify container name]:container name:' \ - '(--all -a)'{-a,--all}'[stop all distroboxes]' \ - '(--yes -Y)'{-Y,--yes}'[non-interactive, stop without asking]' \ - '(--help -h)'{-h,--help}'[show this message]' \ - '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \ - '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ - '(--version -V)'{-V,--version}'[show version]' \ - ':container name:_files' +_distrobox-stop() { + local expl + local -a options + local _db_rcc + + _db_rcc=($(distrobox list | awk -F'|' '$3 ~ /Up/ { gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')) + + options=( + '(-a --all)'{-a,--all}'[stop all distroboxes]' + '(-Y --yes)'{-Y,--yes}'[non-interactive, stop without asking]' + '(-r --root)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' + '(-h --help)'{-h,--help}'[show this message]' + '(-v --verbose)'{-v,--verbose}'[show more verbosity]' + '(-V --version)'{-V,--version}'[show version]' + ) + + _message -r "Stop running distrobox containers." + if [[ -n "$_db_rcc" ]]; then + _arguments -C \ + '*:containers:_distrobox_running_containers' \ + $options[@] + else + _message -r "No running containers." + _arguments $options[@] + fi + +} + +_distrobox-stop diff --git a/completions/zsh/_distrobox-upgrade b/completions/zsh/_distrobox-upgrade old mode 100755 new mode 100644 index ff0929a341..bf52dba571 --- a/completions/zsh/_distrobox-upgrade +++ b/completions/zsh/_distrobox-upgrade @@ -1,10 +1,31 @@ #compdef distrobox-upgrade -_arguments \ - '(--help -h)'{-h,--help}'[show this message]' \ - '(--all -a)'{-a,--all}'[perform for all distroboxes]' \ - '--running[perform only for running distroboxes]' \ - '(--root -r)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' \ - '(--verbose -v)'{-v,--verbose}'[show more verbosity]' \ - '(--version -V)'{-V,--version}'[show version]' \ - ':container name:_files' +_distrobox-upgrade() { + local expl + local -a options + local _db_cc + + _db_cc=("${(@f)$(distrobox list | sed 1d | awk -F'|' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')}") + + options=( + '(-a --all)'{-a,--all}'[upgrade all distroboxes]' + '--running[perform only for running distroboxes]' + '(-r --root)'{-r,--root}'[launch podman/docker/lilipod with root privileges]' + '(-h --help)'{-h,--help}'[show this message]' + '(-v --verbose)'{-v,--verbose}'[show more verbosity]' + '(-V --version)'{-V,--version}'[show version]' + ) + + _message -r "Upgrade distroboxes using container's package manager." + if [[ -n "$_db_cc" ]]; then + _arguments \ + '*:containers:_distrobox_containers' \ + $options[@] + else + _message -r "No containers exist." + _arguments $options[@] + fi + +} + +_distrobox-upgrade diff --git a/completions/zsh/_distrobox_containers b/completions/zsh/_distrobox_containers new file mode 100644 index 0000000000..43ac69c870 --- /dev/null +++ b/completions/zsh/_distrobox_containers @@ -0,0 +1,7 @@ +#autoload + +_distrobox_containers() { + local -a containers + containers=("${(@f)$(distrobox list | sed 1d | awk -F'|' '{print $2}' | sed 's/^[ \t]*//;s/[ \t]*$//')}") + _describe -t containers 'available containers' containers +} diff --git a/completions/zsh/_distrobox_images b/completions/zsh/_distrobox_images new file mode 100644 index 0000000000..93fa195768 --- /dev/null +++ b/completions/zsh/_distrobox_images @@ -0,0 +1,7 @@ +#autoload + +_distrobox_images() { + local -a images + images=("${(@f)$(distrobox-create --compatibility | awk 'NF {print $0}')}") + _wanted images expl 'compatible image' compadd -a images +} diff --git a/completions/zsh/_distrobox_running_containers b/completions/zsh/_distrobox_running_containers new file mode 100644 index 0000000000..9354df7453 --- /dev/null +++ b/completions/zsh/_distrobox_running_containers @@ -0,0 +1,9 @@ +#autoload + +_distrobox_running_containers() { + local -a containers + containers=($(distrobox list | awk -F'|' '$3 ~ /Up/ { gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2 }')) + if (( ${#containers} > 0 )); then + _describe -t running-containers 'running containers' containers + fi +}