diff --git a/dot_zsh/completion/buildah.bash b/dot_zsh/completion/buildah.bash new file mode 100644 index 0000000..0aa7f10 --- /dev/null +++ b/dot_zsh/completion/buildah.bash @@ -0,0 +1,1219 @@ +# bash completion file for buildah command +# +# This script provides completion of: +# - commands and their options +# - filepaths +# +# To enable the completions either: +# - place this file in /usr/share/bash-completion/completions +# or +# - copy this file to e.g. ~/.buildah-completion.sh and add the line +# below to your .bashrc after bash completion features are loaded +# . ~/.buildah-completion.sh +# +# Configuration: +# + +# __buildah_to_alternatives transforms a multiline list of strings into a single line +# string with the words separated by `|`. +# This is used to prepare arguments to __buildah_pos_first_nonflag(). +__buildah_to_alternatives() { + local parts=( $1 ) + local IFS='|' + echo "${parts[*]}" +} + +# __buildah_to_extglob transforms a multiline list of options into an extglob pattern +# suitable for use in case statements. +__buildah_to_extglob() { + local extglob=$( __buildah_to_alternatives "$1" ) + echo "@($extglob)" +} + +# __buildah_pos_first_nonflag finds the position of the first word that is neither +# option nor an option's argument. If there are options that require arguments, +# you should pass a glob describing those options, e.g. "--option1|-o|--option2" +# Use this function to restrict completions to exact positions after the argument list. +__buildah_pos_first_nonflag() { + local argument_flags=$1 + + local counter=$((${subcommand_pos:-${command_pos}} + 1)) + while [ $counter -le $cword ]; do + if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then + (( counter++ )) + # eat "=" in case of --option=arg syntax + [ "${words[$counter]}" = "=" ] && (( counter++ )) + else + case "${words[$counter]}" in + -*) + ;; + *) + break + ;; + esac + fi + + # Bash splits words at "=", retaining "=" as a word, examples: + # "--log-level=error" => 3 words, "--log-opt syslog-facility=daemon" => 4 words + while [ "${words[$counter + 1]}" = "=" ] ; do + counter=$(( counter + 2)) + done + + (( counter++ )) + done + + echo $counter +} + +# Note for developers: +# Please arrange options sorted alphabetically by long name with the short +# options immediately following their corresponding long form. +# This order should be applied to lists, alternatives and code blocks. + +__buildah_previous_extglob_setting=$(shopt -p extglob) +shopt -s extglob + +# __buildah_list_mounted +__buildah_list_mounted() { + COMPREPLY=($(compgen -W "$(buildah mount | awk '{print $1}')" -- $cur)) +} + +__buildah_list_containers() { + COMPREPLY=($(compgen -W "$(buildah containers --format '{{.ContainerName}} {{.ContainerID}}' )" -- $cur)) +} +__buildah_list_images() { + COMPREPLY=($(compgen -W "$(buildah images --format '{{.ID}} {{.Name}}' )" -- $cur)) +} +__buildah_list_images_scratch() { + COMPREPLY=($(compgen -W "$(buildah images --format '{{.ID}} {{.Name}}' ) scratch" -- $cur)) +} +__buildah_list_containers_images() { + COMPREPLY=($(compgen -W "$(buildah containers --format '{{.ContainerName}} {{.ContainerID}}') $(buildah images --format '{{.ID}} {{.Name}}')" -- $cur)) +} + +__buildah_pos_first_nonflag() { + local argument_flags=$1 + + local counter=$((${subcommand_pos:-${command_pos}} + 1)) + while [ $counter -le $cword ]; do + if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then + ((counter++)) + else + case "${words[$counter]}" in + -*) ;; + *) + break + ;; + esac + fi + ((counter++)) + done + + echo $counter +} + +# Transforms a multiline list of strings into a single line string +# with the words separated by "|". +# This is used to prepare arguments to __buildah_pos_first_nonflag(). +__buildah_to_alternatives() { + local parts=($1) + local IFS='|' + echo "${parts[*]}" +} + +# Transforms a multiline list of options into an extglob pattern +# suitable for use in case statements. +__buildah_to_extglob() { + local extglob=$(__buildah_to_alternatives "$1") + echo "@($extglob)" +} + +# Subcommand processing. +# Locates the first occurrence of any of the subcommands contained in the +# first argument. In case of a match, calls the corresponding completion +# function and returns 0. +# If no match is found, 1 is returned. The calling function can then +# continue processing its completion. +# +# TODO if the preceding command has options that accept arguments and an +# argument is equal ot one of the subcommands, this is falsely detected as +# a match. +__buildah_subcommands() { + local subcommands="$1" + + local counter=$(($command_pos + 1)) + while [ $counter -lt $cword ]; do + case "${words[$counter]}" in + $(__buildah_to_extglob "$subcommands") ) +subcommand_pos=$counter +local subcommand=${words[$counter]} +local completions_func=_buildah_${command}_${subcommand} +declare -F $completions_func >/dev/null && $completions_func +return 0 +;; +esac +(( counter++ )) +done +return 1 +} + + # suppress trailing whitespace + __buildah_nospace() { + # compopt is not available in ancient bash versions + type compopt &>/dev/null && compopt -o nospace + } + + + # global options that may appear after the buildah command + _buildah_buildah() { + local boolean_options=" + --help -h + --version -v + " + local options_with_args=" + --registries-conf + --registries-conf-dir + --root + --runroot + --storage-driver + --storage-opt + --userns-uid-map + --userns-gid-map + " + + case "$prev" in + --root | --runroot) + case "$cur" in + *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) + '') + COMPREPLY=($(compgen -W '/' -- "$cur")) + __buildah_nospace + ;; + *) + _filedir + __buildah_nospace + ;; + esac + return + ;; + --storage-driver) + COMPREPLY=($(compgen -W 'devicemapper overlay2' -- "$cur")) + return + ;; + $(__buildah_to_extglob "$options_with_args")) + return + ;; + esac + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + local counter=$(__buildah_pos_first_nonflag $(__buildah_to_extglob "$options_with_args")) + if [ $cword -eq $counter ]; then + COMPREPLY=($(compgen -W "${commands[*]} help" -- "$cur")) + fi + ;; + esac +} + + _buildah_rmi() { + local boolean_options=" + --all + -a + --prune + -p + --force + -f + --help + -h + " + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_images + ;; + esac + } + + _buildah_rm() { + local boolean_options=" + --all + -a + --help + -h + " + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_containers + ;; + esac + } + + _buildah_help() { + local counter=$(__buildah_pos_first_nonflag) + if [ $cword -eq $counter ]; then + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) + fi + } + + _buildah_config() { + local boolean_options=" + --add-history + --help + -h + " + + local options_with_args=" + --annotation + -a + --arch + --author + --cmd + --comment + --created-by + --domainname + --entrypoint + --env + -e + --healthcheck + --healthcheck-interval + --healthcheck-retries + --healthcheck-start-period + --healthcheck-timeout + --history-comment + --hostname + --label + -l + --onbuild + --os + --port + -p + --shell + --stop-signal + --user + -u + --volume + -v + --workingdir + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_containers + ;; + esac + } + + _buildah_commit() { + local boolean_options=" + --help + -h + --disable-compression + -D + --manifest + --quiet + -q + --rm + --squash + --tls-verify + --omit-timestamp + " + + local options_with_args=" + --authfile + --cert-dir + --creds + --format + -f + --iidfile + --sign-by + " + + local all_options="$options_with_args $boolean_options" + + case "$prev" in + --signature-policy) + case "$cur" in + *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) + '') + COMPREPLY=($(compgen -W '/' -- "$cur")) + __buildah_nospace + ;; + *) + _filedir + __buildah_nospace + ;; + esac + return + ;; + + $(__buildah_to_extglob "$options_with_args")) + return + ;; + esac + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_containers + ;; + esac + } + + _buildah_bud() { + local boolean_options=" + --help + -h + --layers + --no-cache + --omit-timestamp + --pull + --pull-always + --pull-never + --quiet + -q + --squash + --tls-verify + " + + local options_with_args=" + --arch + --add-host + --annotation + --authfile + --build-arg + --cap-add + --cap-drop + --cert-dir + --cgroup-parent + --cni-config-dir + --cni-plugin-path + --cpu-period + --cpu-quota + --cpu-shares + --cpuset-cpus + --cpuset-mems + --creds + --decryption-key + --device + --dns-search + --dns + --dns-option + -f + --file + --format + --http-proxy + --ignorefile + --iidfile + --isolation + --ipc + --label + --loglevel + --manifest + -m + --memory + --memory-swap + --net + --network + --no-pivot + --os + --pid + --platform + --runtime + --runtime-flag + --security-opt + --shm-size + --sign-by + -t + --tag + --target + --ulimit + --userns + --userns-uid-map + --userns-gid-map + --userns-uid-map-user + --userns-gid-map-group + --uts + --volume + -v + " + + local all_options="$options_with_args $boolean_options" + + case "$prev" in + --runtime) + COMPREPLY=($(compgen -W 'runc runv' -- "$cur")) + ;; + $(__buildah_to_extglob "$options_with_args")) + return + ;; + esac + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac +} + + _buildah_build_using_dockerfile() { + _buildah_bud "$@" +} + + _buildah_run() { + local boolean_options=" + --add-history + --help + -t + --tty + --terminal + -h + " + + local options_with_args=" + --cap-add + --cap-drop + --cni-config-dir + --cni-plugin-path + --hostname + --ipc + --isolation + --mount + --net + --network + --pid + --runtime + --runtime-flag + --security-opt + --user + --uts + --volume + -v + " + + local all_options="$options_with_args $boolean_options" + + case "$prev" in + --runtime) + COMPREPLY=($(compgen -W 'runc runv' -- "$cur")) + ;; + $(__buildah_to_extglob "$options_with_args")) + return + ;; + esac + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_containers + ;; + esac +} + + _buildah_copy() { + local boolean_options=" + --add-history + --help + -h + --quiet + -q + " + + local options_with_args=" + --chown + --contextdir + --ignorefile + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_add() { + local boolean_options=" + --add-history + --help + -h + --quiet + -q + " + + local options_with_args=" + -chown + --contextdir + --ignorefile + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_unmount() { + _buildah_umount $@ + } + + _buildah_umount() { + local boolean_options=" + --all + -a + --help + -h + " + + local options_with_args=" + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_mounted + ;; + esac + } + + _buildah_pull() { + local boolean_options=" + --all-tags + -a + --help + -h + --quiet + -q + --tls-verify + --remove-signatures + " + + local options_with_args=" + --authfile + --cert-dir + --creds + --decryption-key + --policy + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_push() { + local boolean_options=" + --all + --help + -h + --disable-compression + -D + --quiet + -q + --rm + --tls-verify + --remove-signatures + " + + local options_with_args=" + --authfile + --cert-dir + --creds + --encrypt-layer + --encryption-key + --format + -f + --sign-by + " + + local all_options="$options_with_args $boolean_options" + + case "$prev" in + --signature-policy) + case "$cur" in + *:*) ;; # TODO somehow do _filedir for stuff inside the image, if it's already specified (which is also somewhat difficult to determine) + '') + COMPREPLY=($(compgen -W '/' -- "$cur")) + __buildah_nospace + ;; + *) + _filedir + __buildah_nospace + ;; + esac + return + ;; + + $(__buildah_to_extglob "$options_with_args")) + return + ;; + esac + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_images + ;; + esac + } + + _buildah_logout() { + local boolean_options=" + --help + -h + --all + -a + " + + local options_with_args=" + --authfile + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_login() { + local boolean_options=" + --help + -h + --get-login + --tls-verify + " + + local options_with_args=" + --authfile + --cert-dir + --password string + -p + --password-stdin + --username + -u + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_manifest() { + local boolean_options=" + --help + -h + --all + " + subcommands=" + add + annotate + create + inspect + push + remove + " + __buildah_subcommands "$subcommands" && return + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options " -- "$cur")) + ;; + *) + COMPREPLY=( $( compgen -W "$subcommands" -- "$cur" ) ) + ;; + esac + +} + _buildah_manifest_add() { + local boolean_options=" + --help + -h + --all + --tls-verify + " + + local options_with_args=" + --authfile + --annotation + --arch + --cert-dir + --creds + --features + --os + --os-features + --os-version + --variant + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_manifest_annotate() { + local boolean_options=" + --help + -h + " + + local options_with_args=" + --annotation + --arch + --features + --os + --os-features + --os-version + --variant + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_manifest_create() { + local boolean_options=" + --help + -h + --all + " + + local options_with_args=" + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_manifest_inspect() { + local boolean_options=" + --help + -h + " + + local options_with_args=" + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_manifest_push() { + local boolean_options=" + --help + -h + --all + --remove-signatures + --tls-verify + " + + local options_with_args=" + --authfile + --cert-dir + --creds + --digestfile + --format + -f + --rm + --sign-by + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_manifest_remove() { + local boolean_options=" + --help + -h + " + + local options_with_args=" + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_mount() { + local boolean_options=" + --help + -h + --notruncate + " + + local options_with_args=" + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_containers + ;; + esac + } + + _buildah_ps() { + _buildah_containers + } + +_buildah_list() { + _buildah_containers + } + +_buildah_ls() { + _buildah_containers + } + +_buildah_containers() { + local boolean_options=" + --help + -h + --json + --quiet + -q + --noheading + -n + --notruncate + -a + --all + " + + local options_with_args=" + --filter + -f + --format + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_images() { + local boolean_options=" + --all + -a + --digests + --help + -h + --history + --json + --quiet + -q + --noheading + -n + --no-trunc + --notruncate + " + + local options_with_args=" + --filter + -f + --format + " + + local all_options="$options_with_args $boolean_options" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + esac + } + + _buildah_info() { + local options_with_args=" + --log-level + --D + --format + " + + local all_options="$options_with_args" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$options_with_args" -- "$cur")) + ;; + esac +} + + _buildah_inspect() { + local options_with_args=" + --format + -f + --type + -t + " + + local all_options="$options_with_args" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$options_with_args" -- "$cur")) + ;; + *) + __buildah_list_containers_images + ;; + +esac + } + + _buildah_tag() { + local options_with_args=" + " + + local all_options="$options_with_args" + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$options_with_args" -- "$cur")) + ;; + *) + __buildah_list_images + ;; + esac + } + + _buildah_from() { + local boolean_options=" + --help + -h + --pull + --pull-always + --pull-never + --quiet + -q + --tls-verify + " + + local options_with_args=" + --add-host + --authfile + --cap-add + --cap-drop + --cert-dir + --cgroup-parent + --cidfile + --cni-config-dir + --cni-plugin-path + --cpu-period + --cpu-quota + --cpu-shares + --cpuset-cpus + --cpuset-mems + --creds + --device + --http-proxy + --ipc + --isolation + -m + --memory + --memory-swap + --name + --net + --network + --pid + --security-opt + --shm-size + --ulimit + --userns + --userns-uid-map + --userns-gid-map + --userns-uid-map-user + --userns-gid-map-group + --uts + --volume + " + + + case "$cur" in + -*) + COMPREPLY=($(compgen -W "$boolean_options $options_with_args" -- "$cur")) + ;; + *) + __buildah_list_images_scratch + ;; + esac + } + + _buildah_unshare() { + local boolean_options=" + --help + -h + " + + local options_with_args=" + --mount + " + } + + _buildah_rename() { + local boolean_options=" + --help + -h + " + + local options_with_args=" + " + } + + _buildah_version() { + local boolean_options=" + --help + -h + " + + local options_with_args=" + " + } + + _buildah() { + local previous_extglob_setting=$(shopt -p extglob) + shopt -s extglob + + local commands=( + add + bud + build-using-dockerfile + commit + config + containers + copy + delete + from + images + info + inspect + list + ls + manifest + mount + pull + push + ps + rename + rm + rmi + run + tag + umount + unmount + unshare + version + ) + + COMPREPLY=() + local cur prev words cword + _get_comp_words_by_ref -n : cur prev words cword + + local command='buildah' command_pos=0 subcommand_pos + local counter=1 + while [ $counter -lt $cword ]; do + case "${words[$counter]}" in + $(__buildah_to_extglob "$global_options_with_args") ) + (( counter++ )) + ;; + -*) + ;; + =) + (( counter++ )) + ;; + *) + command="${words[$counter]}" + command_pos=$counter + break + ;; + esac + (( counter++ )) +done + + local binary="${words[0]}" + + local completions_func=_buildah_${command/-/_} + declare -F $completions_func >/dev/null && $completions_func + + eval "$previous_extglob_setting" + return 0 + } + + eval "$__buildah_previous_extglob_setting" + unset __buildah_previous_extglob_setting + + complete -F _buildah buildah diff --git a/dot_zsh/fzf-completion.zsh b/dot_zsh/completion/fzf-completion.zsh similarity index 100% rename from dot_zsh/fzf-completion.zsh rename to dot_zsh/completion/fzf-completion.zsh diff --git a/dot_zsh/completion/podman.zsh b/dot_zsh/completion/podman.zsh new file mode 100644 index 0000000..01ddfa4 --- /dev/null +++ b/dot_zsh/completion/podman.zsh @@ -0,0 +1,161 @@ +#compdef _podman podman + +# zsh completion for podman -*- shell-script -*- + +__podman_debug() +{ + local file="$BASH_COMP_DEBUG_FILE" + if [[ -n ${file} ]]; then + echo "$*" >> "${file}" + fi +} + +_podman() +{ + local shellCompDirectiveError=1 + local shellCompDirectiveNoSpace=2 + local shellCompDirectiveNoFileComp=4 + local shellCompDirectiveFilterFileExt=8 + local shellCompDirectiveFilterDirs=16 + + local lastParam lastChar flagPrefix requestComp out directive compCount comp lastComp + local -a completions + + __podman_debug "\n========= starting completion logic ==========" + __podman_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}" + + # The user could have moved the cursor backwards on the command-line. + # We need to trigger completion from the $CURRENT location, so we need + # to truncate the command-line ($words) up to the $CURRENT location. + # (We cannot use $CURSOR as its value does not work when a command is an alias.) + words=("${=words[1,CURRENT]}") + __podman_debug "Truncated words[*]: ${words[*]}," + + lastParam=${words[-1]} + lastChar=${lastParam[-1]} + __podman_debug "lastParam: ${lastParam}, lastChar: ${lastChar}" + + # For zsh, when completing a flag with an = (e.g., podman -n=) + # completions must be prefixed with the flag + setopt local_options BASH_REMATCH + if [[ "${lastParam}" =~ '-.*=' ]]; then + # We are dealing with a flag with an = + flagPrefix="-P ${BASH_REMATCH}" + fi + + # Prepare the command to obtain completions + requestComp="${words[1]} __complete ${words[2,-1]}" + if [ "${lastChar}" = "" ]; then + # If the last parameter is complete (there is a space following it) + # We add an extra empty parameter so we can indicate this to the go completion code. + __podman_debug "Adding extra empty parameter" + requestComp="${requestComp} \"\"" + fi + + __podman_debug "About to call: eval ${requestComp}" + + # Use eval to handle any environment variables and such + out=$(eval ${requestComp} 2>/dev/null) + __podman_debug "completion output: ${out}" + + # Extract the directive integer following a : from the last line + local lastLine + while IFS='\n' read -r line; do + lastLine=${line} + done < <(printf "%s\n" "${out[@]}") + __podman_debug "last line: ${lastLine}" + + if [ "${lastLine[1]}" = : ]; then + directive=${lastLine[2,-1]} + # Remove the directive including the : and the newline + local suffix + (( suffix=${#lastLine}+2)) + out=${out[1,-$suffix]} + else + # There is no directive specified. Leave $out as is. + __podman_debug "No directive found. Setting do default" + directive=0 + fi + + __podman_debug "directive: ${directive}" + __podman_debug "completions: ${out}" + __podman_debug "flagPrefix: ${flagPrefix}" + + if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then + __podman_debug "Completion received error. Ignoring completions." + return + fi + + compCount=0 + while IFS='\n' read -r comp; do + if [ -n "$comp" ]; then + # If requested, completions are returned with a description. + # The description is preceded by a TAB character. + # For zsh's _describe, we need to use a : instead of a TAB. + # We first need to escape any : as part of the completion itself. + comp=${comp//:/\\:} + + local tab=$(printf '\t') + comp=${comp//$tab/:} + + ((compCount++)) + __podman_debug "Adding completion: ${comp}" + completions+=${comp} + lastComp=$comp + fi + done < <(printf "%s\n" "${out[@]}") + + if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then + # File extension filtering + local filteringCmd + filteringCmd='_files' + for filter in ${completions[@]}; do + if [ ${filter[1]} != '*' ]; then + # zsh requires a glob pattern to do file filtering + filter="\*.$filter" + fi + filteringCmd+=" -g $filter" + done + filteringCmd+=" ${flagPrefix}" + + __podman_debug "File filtering command: $filteringCmd" + _arguments '*:filename:'"$filteringCmd" + elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then + # File completion for directories only + local subDir + subdir="${completions[1]}" + if [ -n "$subdir" ]; then + __podman_debug "Listing directories in $subdir" + pushd "${subdir}" >/dev/null 2>&1 + else + __podman_debug "Listing directories in ." + fi + + _arguments '*:dirname:_files -/'" ${flagPrefix}" + if [ -n "$subdir" ]; then + popd >/dev/null 2>&1 + fi + elif [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ] && [ ${compCount} -eq 1 ]; then + __podman_debug "Activating nospace." + # We can use compadd here as there is no description when + # there is only one completion. + compadd -S '' "${lastComp}" + elif [ ${compCount} -eq 0 ]; then + if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then + __podman_debug "deactivating file completion" + else + # Perform file completion + __podman_debug "activating file completion" + _arguments '*:filename:_files'" ${flagPrefix}" + fi + else + _describe "completions" completions $(echo $flagPrefix) + fi +} + +# don't run the completion function when being source-ed or eval-ed +if [ "$funcstack[1]" = "_podman" ]; then + _podman +fi + +# This file is generated with "podman completion"; see: podman-completion(1) diff --git a/dot_zsh/scw-completion.zsh b/dot_zsh/completion/scw-completion.zsh similarity index 100% rename from dot_zsh/scw-completion.zsh rename to dot_zsh/completion/scw-completion.zsh diff --git a/dot_zsh/dstask-completion.zsh b/dot_zsh/dstask-completion.zsh deleted file mode 100644 index f3a661d..0000000 --- a/dot_zsh/dstask-completion.zsh +++ /dev/null @@ -1,9 +0,0 @@ -#compdef pass -#autoload - - -_dstask() { - compadd $(dstask _completions "${words[@]}") -} - -compdef _dstask dstask diff --git a/dot_zsh/exports.tmpl b/dot_zsh/exports.tmpl index 2d205ee..dd468cb 100644 --- a/dot_zsh/exports.tmpl +++ b/dot_zsh/exports.tmpl @@ -1,6 +1,6 @@ {{- if eq .chezmoi.hostname "taupo" -}} export GOPATH=$HOME/.go -export DEBEMAIL=taziden@flexiden.org +export DEBEMAIL=julien@ilico.org export DEBFULLNAME='Julien Rabier' export PATH=$HOME/projets/tools/bin:$GOPATH/bin:$HOME/.cargo/bin:$HOME/.local/bin:$PATH:/usr/sbin {{- else -}} diff --git a/dot_zshrc.tmpl b/dot_zshrc.tmpl index 4a37117..492bb66 100644 --- a/dot_zshrc.tmpl +++ b/dot_zshrc.tmpl @@ -39,7 +39,7 @@ zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' # ignore case source ~/.zsh/aliases source ~/.zsh/functions source ~/.zsh/exports -source ~/.zsh/fzf-completion.zsh +source ~/.zsh/completion/fzf-completion.zsh {{- if eq .chezmoi.hostname "taupo" }} source ~/.zsh/aliases_taupo @@ -47,9 +47,13 @@ source ~/.zsh/functions_taupo source ~/.config/broot/launcher/bash/br source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh #source /usr/share/doc/fzf/examples/key-bindings.zsh -source ~/.zsh/scw-completion.zsh -source ~/.zsh/dstask-completion.zsh +source ~/.zsh/completion/scw-completion.zsh +source ~/.zsh/completion/podman.zsh +autoload bashcompinit +bashcompinit +source ~/.zsh/completion/buildah.bash {{- end }} + eval "$(zoxide init zsh)" eval "$(starship init zsh)" #source <(antibody init)