Skip to content

Commit

Permalink
zsh completions reworked. fixed not completing container names.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredricocalamari committed Nov 5, 2024
1 parent 18053c2 commit 3848ac9
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 111 deletions.
1 change: 0 additions & 1 deletion completions/zsh/_distrobox
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@ case $state in
;;
esac
esac

1 change: 1 addition & 0 deletions completions/zsh/_distrobox-assemble
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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' \
Expand Down
71 changes: 44 additions & 27 deletions completions/zsh/_distrobox-create
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
44 changes: 33 additions & 11 deletions completions/zsh/_distrobox-enter
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
72 changes: 44 additions & 28 deletions completions/zsh/_distrobox-ephemeral
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion completions/zsh/_distrobox-export
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#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]' \
'(--export-label -el)'{-el,--export-label}'[label to add to exported application name, use "none" to disable]:label:' \
'(--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]' \
Expand Down
42 changes: 33 additions & 9 deletions completions/zsh/_distrobox-generate-entry
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
11 changes: 3 additions & 8 deletions completions/zsh/_distrobox-host-exec
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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]'
1 change: 1 addition & 0 deletions completions/zsh/_distrobox-init
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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:' \
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_distrobox-list
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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]' \
Expand Down
43 changes: 34 additions & 9 deletions completions/zsh/_distrobox-rm
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
38 changes: 29 additions & 9 deletions completions/zsh/_distrobox-stop
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 3848ac9

Please sign in to comment.