mirror of
https://github.com/containers/podman.git
synced 2025-07-04 10:10:32 +08:00
Install the new shell completion logic
Add a new make target (completion) to generate the shell completion scripts. This will generate the scripts for bash, zsh and fish for both podman and podman-remote with `podman completion`. The scripts are put into the completions directory and can be installed system wide with `sudo make install.completions`. This commit replaces the current handwritten scripts for bash and zsh. The `validate.completion` target has been adjusted to make sure nobody edits these scripts directly. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
28
Makefile
28
Makefile
@ -48,6 +48,7 @@ OCI_RUNTIME ?= ""
|
|||||||
|
|
||||||
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
|
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
|
||||||
ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
|
ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
|
||||||
|
FISHINSTALLDIR=${PREFIX}/share/fish/vendor_completions.d
|
||||||
|
|
||||||
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
|
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
|
||||||
|
|
||||||
@ -474,6 +475,15 @@ changelog: ## Generate changelog
|
|||||||
$(shell cat $(TMPFILE) >> changelog.txt)
|
$(shell cat $(TMPFILE) >> changelog.txt)
|
||||||
$(shell rm $(TMPFILE))
|
$(shell rm $(TMPFILE))
|
||||||
|
|
||||||
|
completions: binaries
|
||||||
|
install ${SELINUXOPT} -d -m 755 completions/{bash,zsh,fish}
|
||||||
|
./bin/podman completion bash --no-desc -f completions/bash/podman
|
||||||
|
./bin/podman-remote completion bash --no-desc -f completions/bash/podman-remote
|
||||||
|
./bin/podman completion zsh -f completions/zsh/_podman
|
||||||
|
./bin/podman-remote completion zsh -f completions/zsh/_podman-remote
|
||||||
|
./bin/podman completion fish -f completions/fish/podman.fish
|
||||||
|
./bin/podman-remote completion fish -f completions/fish/podman-remote.fish
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations
|
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations
|
||||||
|
|
||||||
@ -512,8 +522,13 @@ install.man: docs install.man-nobuild
|
|||||||
install.completions:
|
install.completions:
|
||||||
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
|
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
|
||||||
install ${SELINUXOPT} -m 644 completions/bash/podman ${DESTDIR}${BASHINSTALLDIR}
|
install ${SELINUXOPT} -m 644 completions/bash/podman ${DESTDIR}${BASHINSTALLDIR}
|
||||||
|
install ${SELINUXOPT} -m 644 completions/bash/podman-remote ${DESTDIR}${BASHINSTALLDIR}
|
||||||
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
|
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
|
||||||
install ${SELINUXOPT} -m 644 completions/zsh/_podman ${DESTDIR}${ZSHINSTALLDIR}
|
install ${SELINUXOPT} -m 644 completions/zsh/_podman ${DESTDIR}${ZSHINSTALLDIR}
|
||||||
|
install ${SELINUXOPT} -m 644 completions/zsh/_podman-remote ${DESTDIR}${ZSHINSTALLDIR}
|
||||||
|
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${FISHINSTALLDIR}
|
||||||
|
install ${SELINUXOPT} -m 644 completions/fish/podman.fish ${DESTDIR}${FISHINSTALLDIR}
|
||||||
|
install ${SELINUXOPT} -m 644 completions/fish/podman-remote.fish ${DESTDIR}${FISHINSTALLDIR}
|
||||||
|
|
||||||
.PHONY: install.cni
|
.PHONY: install.cni
|
||||||
install.cni:
|
install.cni:
|
||||||
@ -656,9 +671,20 @@ API.md: pkg/varlink/io.podman.varlink
|
|||||||
$(GO) generate ./docs/...
|
$(GO) generate ./docs/...
|
||||||
|
|
||||||
.PHONY: validate.completions
|
.PHONY: validate.completions
|
||||||
validate.completions: completions/bash/podman
|
validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
|
||||||
|
validate.completions:
|
||||||
|
# Check that nobody has manually edited the completion scripts
|
||||||
|
# If this check fails run make completions to restore the correct scripts
|
||||||
|
diff completions/bash/podman <(./bin/podman completion --no-desc bash)
|
||||||
|
diff completions/zsh/_podman <(./bin/podman completion zsh)
|
||||||
|
diff completions/fish/podman.fish <(./bin/podman completion fish)
|
||||||
|
diff completions/bash/podman-remote <(./bin/podman-remote completion --no-desc bash)
|
||||||
|
diff completions/zsh/_podman-remote <(./bin/podman-remote completion zsh)
|
||||||
|
diff completions/fish/podman-remote.fish <(./bin/podman-remote completion fish)
|
||||||
|
# Check if the files can be loaded by the shell
|
||||||
. completions/bash/podman
|
. completions/bash/podman
|
||||||
if [ -x /bin/zsh ]; then /bin/zsh completions/zsh/_podman; fi
|
if [ -x /bin/zsh ]; then /bin/zsh completions/zsh/_podman; fi
|
||||||
|
if [ -x /bin/fish ]; then /bin/fish completions/fish/podman.fish; fi
|
||||||
|
|
||||||
.PHONY: validate
|
.PHONY: validate
|
||||||
validate: gofmt lint .gitvalidation validate.completions man-page-check swagger-check
|
validate: gofmt lint .gitvalidation validate.completions man-page-check swagger-check
|
||||||
|
7
completions/Readme.md
Normal file
7
completions/Readme.md
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Shell completion scripts
|
||||||
|
|
||||||
|
Podman offers shell completion scripts for bash, zsh and fish. The completion scripts are available for both `podman` and `podman-remote`.
|
||||||
|
|
||||||
|
The shell completion scripts are generated by `make completion`, do not edit these files directly. To install them you can run `sudo make install.completions`.
|
||||||
|
|
||||||
|
For information about these sripts see [`man podman-completion`](../docs/source/markdown/podman-completion.1.md)
|
File diff suppressed because it is too large
Load Diff
271
completions/bash/podman-remote
Normal file
271
completions/bash/podman-remote
Normal file
@ -0,0 +1,271 @@
|
|||||||
|
# bash completion for podman-remote -*- shell-script -*-
|
||||||
|
|
||||||
|
__podman-remote_debug()
|
||||||
|
{
|
||||||
|
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
|
||||||
|
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__podman-remote_perform_completion()
|
||||||
|
{
|
||||||
|
__podman-remote_debug
|
||||||
|
__podman-remote_debug "========= starting completion logic =========="
|
||||||
|
__podman-remote_debug "cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}, cword is $cword"
|
||||||
|
|
||||||
|
# The user could have moved the cursor backwards on the command-line.
|
||||||
|
# We need to trigger completion from the $cword location, so we need
|
||||||
|
# to truncate the command-line ($words) up to the $cword location.
|
||||||
|
words=("${words[@]:0:$cword+1}")
|
||||||
|
__podman-remote_debug "Truncated words[*]: ${words[*]},"
|
||||||
|
|
||||||
|
local shellCompDirectiveError=1
|
||||||
|
local shellCompDirectiveNoSpace=2
|
||||||
|
local shellCompDirectiveNoFileComp=4
|
||||||
|
local shellCompDirectiveFilterFileExt=8
|
||||||
|
local shellCompDirectiveFilterDirs=16
|
||||||
|
local shellCompDirectiveLegacyCustomComp=32
|
||||||
|
local shellCompDirectiveLegacyCustomArgsComp=64
|
||||||
|
|
||||||
|
local out requestComp lastParam lastChar comp directive args flagPrefix
|
||||||
|
|
||||||
|
# Prepare the command to request completions for the program.
|
||||||
|
# Calling ${words[0]} instead of directly podman-remote allows to handle aliases
|
||||||
|
args=("${words[@]:1}")
|
||||||
|
requestComp="${words[0]} __completeNoDesc ${args[*]}"
|
||||||
|
|
||||||
|
lastParam=${words[$((${#words[@]}-1))]}
|
||||||
|
lastChar=${lastParam:$((${#lastParam}-1)):1}
|
||||||
|
__podman-remote_debug "lastParam ${lastParam}, lastChar ${lastChar}"
|
||||||
|
|
||||||
|
if [ -z "${cur}" ] && [ "${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 method.
|
||||||
|
__podman-remote_debug "Adding extra empty parameter"
|
||||||
|
requestComp="${requestComp} \"\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# When completing a flag with an = (e.g., podman-remote -n=<TAB>)
|
||||||
|
# bash focuses on the part after the =, so we need to remove
|
||||||
|
# the flag part from $cur
|
||||||
|
if [[ "${cur}" == -*=* ]]; then
|
||||||
|
flagPrefix="${cur%%=*}="
|
||||||
|
cur="${cur#*=}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
__podman-remote_debug "Calling ${requestComp}"
|
||||||
|
# Use eval to handle any environment variables and such
|
||||||
|
out=$(eval "${requestComp}" 2>/dev/null)
|
||||||
|
|
||||||
|
# Extract the directive integer at the very end of the output following a colon (:)
|
||||||
|
directive=${out##*:}
|
||||||
|
# Remove the directive
|
||||||
|
out=${out%:*}
|
||||||
|
if [ "${directive}" = "${out}" ]; then
|
||||||
|
# There is not directive specified
|
||||||
|
directive=0
|
||||||
|
fi
|
||||||
|
__podman-remote_debug "The completion directive is: ${directive}"
|
||||||
|
__podman-remote_debug "The completions are: ${out[*]}"
|
||||||
|
|
||||||
|
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
||||||
|
# Error code. No completion.
|
||||||
|
__podman-remote_debug "Received error from custom completion go code"
|
||||||
|
return
|
||||||
|
else
|
||||||
|
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
||||||
|
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||||
|
__podman-remote_debug "Activating no space"
|
||||||
|
compopt -o nospace
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
||||||
|
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||||
|
__podman-remote_debug "Activating no file completion"
|
||||||
|
compopt +o default
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
||||||
|
# File extension filtering
|
||||||
|
local fullFilter filter filteringCmd
|
||||||
|
|
||||||
|
# Do not use quotes around the $out variable or else newline
|
||||||
|
# characters will be kept.
|
||||||
|
for filter in ${out[*]}; do
|
||||||
|
fullFilter+="$filter|"
|
||||||
|
done
|
||||||
|
|
||||||
|
filteringCmd="_filedir $fullFilter"
|
||||||
|
__podman-remote_debug "File filtering command: $filteringCmd"
|
||||||
|
$filteringCmd
|
||||||
|
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
||||||
|
# File completion for directories only
|
||||||
|
|
||||||
|
# Use printf to strip any trailing newline
|
||||||
|
local subdir
|
||||||
|
subdir=$(printf "%s" "${out[0]}")
|
||||||
|
if [ -n "$subdir" ]; then
|
||||||
|
__podman-remote_debug "Listing directories in $subdir"
|
||||||
|
pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return
|
||||||
|
else
|
||||||
|
__podman-remote_debug "Listing directories in ."
|
||||||
|
_filedir -d
|
||||||
|
fi
|
||||||
|
elif [ $((directive & shellCompDirectiveLegacyCustomComp)) -ne 0 ]; then
|
||||||
|
local cmd
|
||||||
|
__podman-remote_debug "Legacy custom completion. Directive: $directive, cmds: ${out[*]}"
|
||||||
|
|
||||||
|
# The following variables should get their value through the commands
|
||||||
|
# we have received as completions and are parsing below.
|
||||||
|
local last_command
|
||||||
|
local nouns
|
||||||
|
|
||||||
|
# Execute every command received
|
||||||
|
while IFS='' read -r cmd; do
|
||||||
|
__podman-remote_debug "About to execute: $cmd"
|
||||||
|
eval "$cmd"
|
||||||
|
done < <(printf "%s\n" "${out[@]}")
|
||||||
|
|
||||||
|
__podman-remote_debug "last_command: $last_command"
|
||||||
|
__podman-remote_debug "nouns[0]: ${nouns[0]}, nouns[1]: ${nouns[1]}"
|
||||||
|
|
||||||
|
if [ $((directive & shellCompDirectiveLegacyCustomArgsComp)) -ne 0 ]; then
|
||||||
|
# We should call the global legacy custom completion function, if it is defined
|
||||||
|
if declare -F __podman-remote_custom_func >/dev/null; then
|
||||||
|
# Use command name qualified legacy custom func
|
||||||
|
__podman-remote_debug "About to call: __podman-remote_custom_func"
|
||||||
|
__podman-remote_custom_func
|
||||||
|
elif declare -F __custom_func >/dev/null; then
|
||||||
|
# Otherwise fall back to unqualified legacy custom func for compatibility
|
||||||
|
__podman-remote_debug "About to call: __custom_func"
|
||||||
|
__custom_func
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
local tab
|
||||||
|
tab=$(printf '\t')
|
||||||
|
local longest=0
|
||||||
|
# Look for the longest completion so that we can format things nicely
|
||||||
|
while IFS='' read -r comp; do
|
||||||
|
comp=${comp%%$tab*}
|
||||||
|
if ((${#comp}>longest)); then
|
||||||
|
longest=${#comp}
|
||||||
|
fi
|
||||||
|
done < <(printf "%s\n" "${out[@]}")
|
||||||
|
|
||||||
|
local completions=()
|
||||||
|
while IFS='' read -r comp; do
|
||||||
|
if [ -z "$comp" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
__podman-remote_debug "Original comp: $comp"
|
||||||
|
comp="$(__podman-remote_format_comp_descriptions "$comp" "$longest")"
|
||||||
|
__podman-remote_debug "Final comp: $comp"
|
||||||
|
completions+=("$comp")
|
||||||
|
done < <(printf "%s\n" "${out[@]}")
|
||||||
|
|
||||||
|
while IFS='' read -r comp; do
|
||||||
|
# Although this script should only be used for bash
|
||||||
|
# there may be programs that still convert the bash
|
||||||
|
# script into a zsh one. To continue supporting those
|
||||||
|
# programs, we do this single adaptation for zsh
|
||||||
|
if [ -n "${ZSH_VERSION}" ]; then
|
||||||
|
# zsh completion needs --flag= prefix
|
||||||
|
COMPREPLY+=("$flagPrefix$comp")
|
||||||
|
else
|
||||||
|
COMPREPLY+=("$comp")
|
||||||
|
fi
|
||||||
|
done < <(compgen -W "${completions[*]}" -- "$cur")
|
||||||
|
|
||||||
|
# If there is a single completion left, remove the description text
|
||||||
|
if [ ${#COMPREPLY[*]} -eq 1 ]; then
|
||||||
|
__podman-remote_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
|
||||||
|
comp="${COMPREPLY[0]%% *}"
|
||||||
|
__podman-remote_debug "Removed description from single completion, which is now: ${comp}"
|
||||||
|
COMPREPLY=()
|
||||||
|
COMPREPLY+=("$comp")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
__podman-remote_handle_special_char "$cur" :
|
||||||
|
__podman-remote_handle_special_char "$cur" =
|
||||||
|
}
|
||||||
|
|
||||||
|
__podman-remote_handle_special_char()
|
||||||
|
{
|
||||||
|
local comp="$1"
|
||||||
|
local char=$2
|
||||||
|
if [[ "$comp" == *${char}* && "$COMP_WORDBREAKS" == *${char}* ]]; then
|
||||||
|
local word=${comp%"${comp##*${char}}"}
|
||||||
|
local idx=${#COMPREPLY[*]}
|
||||||
|
while [[ $((--idx)) -ge 0 ]]; do
|
||||||
|
COMPREPLY[$idx]=${COMPREPLY[$idx]#"$word"}
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__podman-remote_format_comp_descriptions()
|
||||||
|
{
|
||||||
|
local tab
|
||||||
|
tab=$(printf '\t')
|
||||||
|
local comp="$1"
|
||||||
|
local longest=$2
|
||||||
|
|
||||||
|
# Properly format the description string which follows a tab character if there is one
|
||||||
|
if [[ "$comp" == *$tab* ]]; then
|
||||||
|
desc=${comp#*$tab}
|
||||||
|
comp=${comp%%$tab*}
|
||||||
|
|
||||||
|
# $COLUMNS stores the current shell width.
|
||||||
|
# Remove an extra 4 because we add 2 spaces and 2 parentheses.
|
||||||
|
maxdesclength=$(( COLUMNS - longest - 4 ))
|
||||||
|
|
||||||
|
# Make sure we can fit a description of at least 8 characters
|
||||||
|
# if we are to align the descriptions.
|
||||||
|
if [[ $maxdesclength -gt 8 ]]; then
|
||||||
|
# Add the proper number of spaces to align the descriptions
|
||||||
|
for ((i = ${#comp} ; i < longest ; i++)); do
|
||||||
|
comp+=" "
|
||||||
|
done
|
||||||
|
else
|
||||||
|
# Don't pad the descriptions so we can fit more text after the completion
|
||||||
|
maxdesclength=$(( COLUMNS - ${#comp} - 4 ))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If there is enough space for any description text,
|
||||||
|
# truncate the descriptions that are too long for the shell width
|
||||||
|
if [ $maxdesclength -gt 0 ]; then
|
||||||
|
if [ ${#desc} -gt $maxdesclength ]; then
|
||||||
|
desc=${desc:0:$(( maxdesclength - 1 ))}
|
||||||
|
desc+="…"
|
||||||
|
fi
|
||||||
|
comp+=" ($desc)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Must use printf to escape all special characters
|
||||||
|
printf "%q" "${comp}"
|
||||||
|
}
|
||||||
|
|
||||||
|
__start_podman-remote()
|
||||||
|
{
|
||||||
|
local cur prev words cword
|
||||||
|
|
||||||
|
COMPREPLY=()
|
||||||
|
_get_comp_words_by_ref -n "=:" cur prev words cword
|
||||||
|
|
||||||
|
__podman-remote_perform_completion
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $(type -t compopt) = "builtin" ]]; then
|
||||||
|
complete -o default -F __start_podman-remote podman-remote
|
||||||
|
else
|
||||||
|
complete -o default -o nospace -F __start_podman-remote podman-remote
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ex: ts=4 sw=4 et filetype=sh
|
||||||
|
|
||||||
|
# This file is generated with "podman-remote completion"; see: podman-completion(1)
|
182
completions/fish/podman-remote.fish
Normal file
182
completions/fish/podman-remote.fish
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
# fish completion for podman-remote -*- shell-script -*-
|
||||||
|
|
||||||
|
function __podman_remote_debug
|
||||||
|
set file "$BASH_COMP_DEBUG_FILE"
|
||||||
|
if test -n "$file"
|
||||||
|
echo "$argv" >> $file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __podman_remote_perform_completion
|
||||||
|
__podman_remote_debug "Starting __podman_remote_perform_completion"
|
||||||
|
|
||||||
|
set args (string split -- " " (commandline -c))
|
||||||
|
set lastArg "$args[-1]"
|
||||||
|
|
||||||
|
__podman_remote_debug "args: $args"
|
||||||
|
__podman_remote_debug "last arg: $lastArg"
|
||||||
|
|
||||||
|
set emptyArg ""
|
||||||
|
if test -z "$lastArg"
|
||||||
|
__podman_remote_debug "Setting emptyArg"
|
||||||
|
set emptyArg \"\"
|
||||||
|
end
|
||||||
|
__podman_remote_debug "emptyArg: $emptyArg"
|
||||||
|
|
||||||
|
if not type -q "$args[1]"
|
||||||
|
# This can happen when "complete --do-complete podman-remote" is called when running this script.
|
||||||
|
__podman_remote_debug "Cannot find $args[1]. No completions."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
set requestComp "$args[1] __complete $args[2..-1] $emptyArg"
|
||||||
|
__podman_remote_debug "Calling $requestComp"
|
||||||
|
|
||||||
|
set results (eval $requestComp 2> /dev/null)
|
||||||
|
set comps $results[1..-2]
|
||||||
|
set directiveLine $results[-1]
|
||||||
|
|
||||||
|
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
||||||
|
# completions must be prefixed with the flag
|
||||||
|
set flagPrefix (string match -r -- '-.*=' "$lastArg")
|
||||||
|
|
||||||
|
__podman_remote_debug "Comps: $comps"
|
||||||
|
__podman_remote_debug "DirectiveLine: $directiveLine"
|
||||||
|
__podman_remote_debug "flagPrefix: $flagPrefix"
|
||||||
|
|
||||||
|
for comp in $comps
|
||||||
|
printf "%s%s\n" "$flagPrefix" "$comp"
|
||||||
|
end
|
||||||
|
|
||||||
|
printf "%s\n" "$directiveLine"
|
||||||
|
end
|
||||||
|
|
||||||
|
# This function does two things:
|
||||||
|
# - Obtain the completions and store them in the global __podman_remote_comp_results
|
||||||
|
# - Return false if file completion should be performed
|
||||||
|
function __podman_remote_prepare_completions
|
||||||
|
__podman_remote_debug ""
|
||||||
|
__podman_remote_debug "========= starting completion logic =========="
|
||||||
|
|
||||||
|
# Start fresh
|
||||||
|
set --erase __podman_remote_comp_results
|
||||||
|
|
||||||
|
set results (__podman_remote_perform_completion)
|
||||||
|
__podman_remote_debug "Completion results: $results"
|
||||||
|
|
||||||
|
if test -z "$results"
|
||||||
|
__podman_remote_debug "No completion, probably due to a failure"
|
||||||
|
# Might as well do file completion, in case it helps
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set directive (string sub --start 2 $results[-1])
|
||||||
|
set --global __podman_remote_comp_results $results[1..-2]
|
||||||
|
|
||||||
|
__podman_remote_debug "Completions are: $__podman_remote_comp_results"
|
||||||
|
__podman_remote_debug "Directive is: $directive"
|
||||||
|
|
||||||
|
set shellCompDirectiveError 1
|
||||||
|
set shellCompDirectiveNoSpace 2
|
||||||
|
set shellCompDirectiveNoFileComp 4
|
||||||
|
set shellCompDirectiveFilterFileExt 8
|
||||||
|
set shellCompDirectiveFilterDirs 16
|
||||||
|
set shellCompDirectiveLegacyCustomComp 32
|
||||||
|
set shellCompDirectiveLegacyCustomArgsComp 64
|
||||||
|
|
||||||
|
if test -z "$directive"
|
||||||
|
set directive 0
|
||||||
|
end
|
||||||
|
|
||||||
|
set compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
||||||
|
if test $compErr -eq 1
|
||||||
|
__podman_remote_debug "Received error directive: aborting."
|
||||||
|
# Might as well do file completion, in case it helps
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set legacyCustom (math (math --scale 0 $directive / $shellCompDirectiveLegacyCustomComp) % 2)
|
||||||
|
set legacyCustomArgs (math (math --scale 0 $directive / $shellCompDirectiveLegacyCustomArgsComp) % 2)
|
||||||
|
if test $legacyCustom -eq 1; or test $legacyCustomArgs -eq 1
|
||||||
|
__podman_remote_debug "Legacy bash custom completion not applicable to fish"
|
||||||
|
# Do full file completion instead
|
||||||
|
set --global __podman_remote_comp_do_file_comp 1
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
||||||
|
set dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
||||||
|
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
||||||
|
__podman_remote_debug "File extension filtering or directory filtering not supported"
|
||||||
|
# Do full file completion instead
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
||||||
|
set nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
||||||
|
|
||||||
|
__podman_remote_debug "nospace: $nospace, nofiles: $nofiles"
|
||||||
|
|
||||||
|
# If we want to prevent a space, or if file completion is NOT disabled,
|
||||||
|
# we need to count the number of valid completions.
|
||||||
|
# To do so, we will filter on prefix as the completions we have received
|
||||||
|
# may not already be filtered so as to allow fish to match on different
|
||||||
|
# criteria than prefix.
|
||||||
|
if test $nospace -ne 0; or test $nofiles -eq 0
|
||||||
|
set prefix (commandline -t)
|
||||||
|
__podman_remote_debug "prefix: $prefix"
|
||||||
|
|
||||||
|
set completions
|
||||||
|
for comp in $__podman_remote_comp_results
|
||||||
|
if test (string match -e -r "^$prefix" "$comp")
|
||||||
|
set -a completions $comp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
set --global __podman_remote_comp_results $completions
|
||||||
|
__podman_remote_debug "Filtered completions are: $__podman_remote_comp_results"
|
||||||
|
|
||||||
|
# Important not to quote the variable for count to work
|
||||||
|
set numComps (count $__podman_remote_comp_results)
|
||||||
|
__podman_remote_debug "numComps: $numComps"
|
||||||
|
|
||||||
|
if test $numComps -eq 1; and test $nospace -ne 0
|
||||||
|
# To support the "nospace" directive we trick the shell
|
||||||
|
# by outputting an extra, longer completion.
|
||||||
|
# We must first split on \t to get rid of the descriptions because
|
||||||
|
# the extra character we add to the fake second completion must be
|
||||||
|
# before the description. We don't need descriptions anyway since
|
||||||
|
# there is only a single real completion which the shell will expand
|
||||||
|
# immediately.
|
||||||
|
__podman_remote_debug "Adding second completion to perform nospace directive"
|
||||||
|
set split (string split --max 1 \t $__podman_remote_comp_results[1])
|
||||||
|
set --global __podman_remote_comp_results $split[1] $split[1].
|
||||||
|
__podman_remote_debug "Completions are now: $__podman_remote_comp_results"
|
||||||
|
end
|
||||||
|
|
||||||
|
if test $numComps -eq 0; and test $nofiles -eq 0
|
||||||
|
# To be consistent with bash and zsh, we only trigger file
|
||||||
|
# completion when there are no other completions
|
||||||
|
__podman_remote_debug "Requesting file completion"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
||||||
|
# so we can properly delete any completions provided by another script.
|
||||||
|
# The space after the the program name is essential to trigger completion for the program
|
||||||
|
# and not completion of the program name itself.
|
||||||
|
complete --do-complete "podman-remote " > /dev/null 2>&1
|
||||||
|
# Using '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
||||||
|
|
||||||
|
# Remove any pre-existing completions for the program since we will be handling all of them.
|
||||||
|
complete -c podman-remote -e
|
||||||
|
|
||||||
|
# The call to __podman_remote_prepare_completions will setup __podman_remote_comp_results
|
||||||
|
# which provides the program's completion choices.
|
||||||
|
complete -c podman-remote -n '__podman_remote_prepare_completions' -f -a '$__podman_remote_comp_results'
|
||||||
|
|
||||||
|
|
||||||
|
# This file is generated with "podman-remote completion"; see: podman-completion(1)
|
182
completions/fish/podman.fish
Normal file
182
completions/fish/podman.fish
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
# fish completion for podman -*- shell-script -*-
|
||||||
|
|
||||||
|
function __podman_debug
|
||||||
|
set file "$BASH_COMP_DEBUG_FILE"
|
||||||
|
if test -n "$file"
|
||||||
|
echo "$argv" >> $file
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __podman_perform_completion
|
||||||
|
__podman_debug "Starting __podman_perform_completion"
|
||||||
|
|
||||||
|
set args (string split -- " " (commandline -c))
|
||||||
|
set lastArg "$args[-1]"
|
||||||
|
|
||||||
|
__podman_debug "args: $args"
|
||||||
|
__podman_debug "last arg: $lastArg"
|
||||||
|
|
||||||
|
set emptyArg ""
|
||||||
|
if test -z "$lastArg"
|
||||||
|
__podman_debug "Setting emptyArg"
|
||||||
|
set emptyArg \"\"
|
||||||
|
end
|
||||||
|
__podman_debug "emptyArg: $emptyArg"
|
||||||
|
|
||||||
|
if not type -q "$args[1]"
|
||||||
|
# This can happen when "complete --do-complete podman" is called when running this script.
|
||||||
|
__podman_debug "Cannot find $args[1]. No completions."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
set requestComp "$args[1] __complete $args[2..-1] $emptyArg"
|
||||||
|
__podman_debug "Calling $requestComp"
|
||||||
|
|
||||||
|
set results (eval $requestComp 2> /dev/null)
|
||||||
|
set comps $results[1..-2]
|
||||||
|
set directiveLine $results[-1]
|
||||||
|
|
||||||
|
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
||||||
|
# completions must be prefixed with the flag
|
||||||
|
set flagPrefix (string match -r -- '-.*=' "$lastArg")
|
||||||
|
|
||||||
|
__podman_debug "Comps: $comps"
|
||||||
|
__podman_debug "DirectiveLine: $directiveLine"
|
||||||
|
__podman_debug "flagPrefix: $flagPrefix"
|
||||||
|
|
||||||
|
for comp in $comps
|
||||||
|
printf "%s%s\n" "$flagPrefix" "$comp"
|
||||||
|
end
|
||||||
|
|
||||||
|
printf "%s\n" "$directiveLine"
|
||||||
|
end
|
||||||
|
|
||||||
|
# This function does two things:
|
||||||
|
# - Obtain the completions and store them in the global __podman_comp_results
|
||||||
|
# - Return false if file completion should be performed
|
||||||
|
function __podman_prepare_completions
|
||||||
|
__podman_debug ""
|
||||||
|
__podman_debug "========= starting completion logic =========="
|
||||||
|
|
||||||
|
# Start fresh
|
||||||
|
set --erase __podman_comp_results
|
||||||
|
|
||||||
|
set results (__podman_perform_completion)
|
||||||
|
__podman_debug "Completion results: $results"
|
||||||
|
|
||||||
|
if test -z "$results"
|
||||||
|
__podman_debug "No completion, probably due to a failure"
|
||||||
|
# Might as well do file completion, in case it helps
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set directive (string sub --start 2 $results[-1])
|
||||||
|
set --global __podman_comp_results $results[1..-2]
|
||||||
|
|
||||||
|
__podman_debug "Completions are: $__podman_comp_results"
|
||||||
|
__podman_debug "Directive is: $directive"
|
||||||
|
|
||||||
|
set shellCompDirectiveError 1
|
||||||
|
set shellCompDirectiveNoSpace 2
|
||||||
|
set shellCompDirectiveNoFileComp 4
|
||||||
|
set shellCompDirectiveFilterFileExt 8
|
||||||
|
set shellCompDirectiveFilterDirs 16
|
||||||
|
set shellCompDirectiveLegacyCustomComp 32
|
||||||
|
set shellCompDirectiveLegacyCustomArgsComp 64
|
||||||
|
|
||||||
|
if test -z "$directive"
|
||||||
|
set directive 0
|
||||||
|
end
|
||||||
|
|
||||||
|
set compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
||||||
|
if test $compErr -eq 1
|
||||||
|
__podman_debug "Received error directive: aborting."
|
||||||
|
# Might as well do file completion, in case it helps
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set legacyCustom (math (math --scale 0 $directive / $shellCompDirectiveLegacyCustomComp) % 2)
|
||||||
|
set legacyCustomArgs (math (math --scale 0 $directive / $shellCompDirectiveLegacyCustomArgsComp) % 2)
|
||||||
|
if test $legacyCustom -eq 1; or test $legacyCustomArgs -eq 1
|
||||||
|
__podman_debug "Legacy bash custom completion not applicable to fish"
|
||||||
|
# Do full file completion instead
|
||||||
|
set --global __podman_comp_do_file_comp 1
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
||||||
|
set dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
||||||
|
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
||||||
|
__podman_debug "File extension filtering or directory filtering not supported"
|
||||||
|
# Do full file completion instead
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
||||||
|
set nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
||||||
|
|
||||||
|
__podman_debug "nospace: $nospace, nofiles: $nofiles"
|
||||||
|
|
||||||
|
# If we want to prevent a space, or if file completion is NOT disabled,
|
||||||
|
# we need to count the number of valid completions.
|
||||||
|
# To do so, we will filter on prefix as the completions we have received
|
||||||
|
# may not already be filtered so as to allow fish to match on different
|
||||||
|
# criteria than prefix.
|
||||||
|
if test $nospace -ne 0; or test $nofiles -eq 0
|
||||||
|
set prefix (commandline -t)
|
||||||
|
__podman_debug "prefix: $prefix"
|
||||||
|
|
||||||
|
set completions
|
||||||
|
for comp in $__podman_comp_results
|
||||||
|
if test (string match -e -r "^$prefix" "$comp")
|
||||||
|
set -a completions $comp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
set --global __podman_comp_results $completions
|
||||||
|
__podman_debug "Filtered completions are: $__podman_comp_results"
|
||||||
|
|
||||||
|
# Important not to quote the variable for count to work
|
||||||
|
set numComps (count $__podman_comp_results)
|
||||||
|
__podman_debug "numComps: $numComps"
|
||||||
|
|
||||||
|
if test $numComps -eq 1; and test $nospace -ne 0
|
||||||
|
# To support the "nospace" directive we trick the shell
|
||||||
|
# by outputting an extra, longer completion.
|
||||||
|
# We must first split on \t to get rid of the descriptions because
|
||||||
|
# the extra character we add to the fake second completion must be
|
||||||
|
# before the description. We don't need descriptions anyway since
|
||||||
|
# there is only a single real completion which the shell will expand
|
||||||
|
# immediately.
|
||||||
|
__podman_debug "Adding second completion to perform nospace directive"
|
||||||
|
set split (string split --max 1 \t $__podman_comp_results[1])
|
||||||
|
set --global __podman_comp_results $split[1] $split[1].
|
||||||
|
__podman_debug "Completions are now: $__podman_comp_results"
|
||||||
|
end
|
||||||
|
|
||||||
|
if test $numComps -eq 0; and test $nofiles -eq 0
|
||||||
|
# To be consistent with bash and zsh, we only trigger file
|
||||||
|
# completion when there are no other completions
|
||||||
|
__podman_debug "Requesting file completion"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
||||||
|
# so we can properly delete any completions provided by another script.
|
||||||
|
# The space after the the program name is essential to trigger completion for the program
|
||||||
|
# and not completion of the program name itself.
|
||||||
|
complete --do-complete "podman " > /dev/null 2>&1
|
||||||
|
# Using '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
||||||
|
|
||||||
|
# Remove any pre-existing completions for the program since we will be handling all of them.
|
||||||
|
complete -c podman -e
|
||||||
|
|
||||||
|
# The call to __podman_prepare_completions will setup __podman_comp_results
|
||||||
|
# which provides the program's completion choices.
|
||||||
|
complete -c podman -n '__podman_prepare_completions' -f -a '$__podman_comp_results'
|
||||||
|
|
||||||
|
|
||||||
|
# This file is generated with "podman completion"; see: podman-completion(1)
|
@ -1,379 +1,181 @@
|
|||||||
#compdef podman
|
#compdef _podman podman
|
||||||
|
|
||||||
# To get zsh to reread this file: unset -f _podman;rm -f ~/.zcompdump;compinit
|
# zsh completion for podman -*- shell-script -*-
|
||||||
|
|
||||||
# On rereads, reset cache. (Not that the caching works, but some day it might)
|
__podman_debug()
|
||||||
unset -m '_podman_*'
|
{
|
||||||
|
local file="$BASH_COMP_DEBUG_FILE"
|
||||||
###############################################################################
|
if [[ -n ${file} ]]; then
|
||||||
# BEGIN 'podman help' parsers -- for options, subcommands, and usage
|
echo "$*" >> "${file}"
|
||||||
|
fi
|
||||||
# Run 'podman XX --help', set _podman_commands to a formatted list of cmds
|
|
||||||
_read_podman_commands() {
|
|
||||||
local line
|
|
||||||
|
|
||||||
# Cache: the intention here is to run each 'podman help' only once.
|
|
||||||
# Unfortunately it doesn't seem to actually be working: even though
|
|
||||||
# I can see the var_ref in my shell, it's not visible here.
|
|
||||||
local _var_ref=_podman_commands_"${*// /_}"
|
|
||||||
typeset -ga _podman_commands
|
|
||||||
_podman_commands=(${(P)_var_ref})
|
|
||||||
(( $#_podman_commands )) && return
|
|
||||||
|
|
||||||
_call_program podman podman "$@" --help |\
|
|
||||||
sed -n -e '0,/^Available Commands/d' -e '/^[A-Z]/q;p' |\
|
|
||||||
sed -e 's/^ \+\([^ ]\+\) \+/\1:/' |\
|
|
||||||
egrep . | while read line; do
|
|
||||||
_podman_commands+=($line)
|
|
||||||
done
|
|
||||||
|
|
||||||
eval "typeset -ga $_var_ref"
|
|
||||||
eval "$_var_ref=(\$_podman_commands)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Run 'podman XX --help', set _podman_option_list to a formatted list
|
_podman()
|
||||||
# of option options for XX
|
{
|
||||||
_read_podman_options() {
|
local shellCompDirectiveError=1
|
||||||
local line
|
local shellCompDirectiveNoSpace=2
|
||||||
|
local shellCompDirectiveNoFileComp=4
|
||||||
|
local shellCompDirectiveFilterFileExt=8
|
||||||
|
local shellCompDirectiveFilterDirs=16
|
||||||
|
local shellCompDirectiveLegacyCustomComp=32
|
||||||
|
local shellCompDirectiveLegacyCustomArgsComp=64
|
||||||
|
|
||||||
local _var_ref=_podman_options_"${*// /_}"
|
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace
|
||||||
eval "typeset -ga ${_var_ref}"
|
local -a completions
|
||||||
typeset -ga _podman_option_list
|
|
||||||
_podman_option_list=(${(P)_var_ref})
|
|
||||||
(( $#_podman_option_list )) && return
|
|
||||||
|
|
||||||
# Extract the Options; strip leading whitespace; pack '-f, --foo'
|
__podman_debug "\n========= starting completion logic =========="
|
||||||
# as '-f,--foo' (no space); then add '=' to '--foo string'.
|
__podman_debug "CURRENT: ${CURRENT}, words[*]: ${words[*]}"
|
||||||
# The result will be, e.g. '-f,--foo=string Description of Option'
|
|
||||||
_call_program podman podman "$@" --help |\
|
# The user could have moved the cursor backwards on the command-line.
|
||||||
sed -n -e '0,/^Options:/d' -e '/^$/q;p' |\
|
# We need to trigger completion from the $CURRENT location, so we need
|
||||||
grep '^ \+-' |\
|
# to truncate the command-line ($words) up to the $CURRENT location.
|
||||||
sed -e 's/^ *//' -e 's/^\(-.,\) --/\1--/' |\
|
# (We cannot use $CURSOR as its value does not work when a command is an alias.)
|
||||||
sed -e 's/^\(-[^ ]\+\) \([^ ]\+\) /\1=\2 /' |\
|
words=("${=words[1,CURRENT]}")
|
||||||
while read options desc;do
|
__podman_debug "Truncated words[*]: ${words[*]},"
|
||||||
# options like --foo=string: split into --foo & string
|
|
||||||
local -a tmpa
|
lastParam=${words[-1]}
|
||||||
local optval=
|
lastChar=${lastParam[-1]}
|
||||||
tmpa=(${(s.=.)options})
|
__podman_debug "lastParam: ${lastParam}, lastChar: ${lastChar}"
|
||||||
if [ -n "$tmpa[2]" ]; then
|
|
||||||
options=$tmpa[1]
|
# For zsh, when completing a flag with an = (e.g., podman -n=<TAB>)
|
||||||
optval=$tmpa[2]
|
# 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
|
fi
|
||||||
|
|
||||||
# 'podman attach --detach-keys' includes ']' in help msg
|
# Prepare the command to obtain completions
|
||||||
desc=${desc//\]/\\]}
|
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
|
||||||
|
|
||||||
for option in ${(s:,:)options}; do
|
__podman_debug "About to call: eval ${requestComp}"
|
||||||
if [ -n "$optval" ]; then
|
|
||||||
_podman_option_list+=("${option}[$desc]:$(_podman_find_helper ${options} ${optval} ${desc})")
|
# 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
|
else
|
||||||
_podman_option_list+=("${option}[$desc]")
|
# There is no directive specified. Leave $out as is.
|
||||||
|
__podman_debug "No directive found. Setting do default"
|
||||||
|
directive=0
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
done
|
|
||||||
|
|
||||||
eval "typeset -ga $_var_ref=(\$_podman_option_list)"
|
__podman_debug "directive: ${directive}"
|
||||||
}
|
__podman_debug "completions: ${out}"
|
||||||
|
__podman_debug "flagPrefix: ${flagPrefix}"
|
||||||
|
|
||||||
# Run 'podman XXX --help', set _podman_usage to the line after "Usage:"
|
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
||||||
_read_podman_usage() {
|
__podman_debug "Completion received error. Ignoring completions."
|
||||||
local _var_ref=_podman_usage_"${*// /_}"
|
|
||||||
typeset -ga _podman_usage
|
|
||||||
_podman_usage=${(P)_var_ref}
|
|
||||||
(( $#_podman_usage )) && return
|
|
||||||
|
|
||||||
_podman_usage=$(_call_program podman podman "$@" --help |\
|
|
||||||
grep -A1 'Usage:'|\
|
|
||||||
tail -1 |\
|
|
||||||
sed -e 's/^ *//')
|
|
||||||
|
|
||||||
eval "typeset -ga $_var_ref"
|
|
||||||
eval "$_var_ref=\$_podman_usage"
|
|
||||||
}
|
|
||||||
|
|
||||||
# END 'podman help' parsers
|
|
||||||
###############################################################################
|
|
||||||
# BEGIN custom helpers for individual option arguments
|
|
||||||
|
|
||||||
# Find a zsh helper for a given option or command-line option
|
|
||||||
_podman_find_helper() {
|
|
||||||
local options=$1
|
|
||||||
local optval=$2
|
|
||||||
local desc=$3
|
|
||||||
local helper=
|
|
||||||
|
|
||||||
# Yes, this is a lot of hardcoding. IMHO it's still better than
|
|
||||||
# hardcoding every possible podman option.
|
|
||||||
# FIXME: there are many more options that could use helpers.
|
|
||||||
if expr "$desc" : ".*[Dd]irectory" >/dev/null; then
|
|
||||||
optval="directory"
|
|
||||||
helper="_files -/"
|
|
||||||
elif expr "$desc" : ".*[Pp]ath" >/dev/null; then
|
|
||||||
optval="path"
|
|
||||||
helper=_files
|
|
||||||
# For messages like 'restart policy ("always"|"no"|"on-failure")
|
|
||||||
elif optlist=$(expr "$desc" : '.*(\(\"[^\\)]\+|[^\\)]\+\"\))' 2>/dev/null); then
|
|
||||||
optval=${${options##--}//-/ } # "--log-level" => "log level"
|
|
||||||
optlist=${optlist//\"/} # "a"|"b"|"c" => a|b|c
|
|
||||||
optlist=${optlist//\|/ } # a|b|c => a b c
|
|
||||||
# FIXME: how to present values _in order_, not sorted alphabetically?
|
|
||||||
helper="($optlist)"
|
|
||||||
fi
|
|
||||||
echo "$optval:$helper"
|
|
||||||
}
|
|
||||||
|
|
||||||
# END custom helpers for individual option arguments
|
|
||||||
###############################################################################
|
|
||||||
# BEGIN helpers for command-line args (containers, images)
|
|
||||||
|
|
||||||
__podman_helper_generic() {
|
|
||||||
local expl line
|
|
||||||
local -a results
|
|
||||||
|
|
||||||
local foo1=$1; shift
|
|
||||||
local name=$2; shift
|
|
||||||
|
|
||||||
_call_program $foo1 podman "$@" |\
|
|
||||||
while read line; do
|
|
||||||
results+=(${=line})
|
|
||||||
done
|
|
||||||
|
|
||||||
_wanted $foo1 expl $name compadd ${(u)results}
|
|
||||||
}
|
|
||||||
|
|
||||||
_podman_helper_image() {
|
|
||||||
__podman_helper_generic podman-images 'images' \
|
|
||||||
images --format '{{.ID}}\ {{.Repository}}:{{.Tag}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
# FIXME: at some point, distinguish between running & stopped containers
|
|
||||||
_podman_helper_container() {
|
|
||||||
__podman_helper_generic podman-containers 'containers' \
|
|
||||||
ps -a --format '{{.Names}}\ {{.ID}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
_podman_helper_pod() {
|
|
||||||
__podman_helper_generic podman-pods 'pods' pod list --format '{{.Name}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
_podman_helper_volume() {
|
|
||||||
__podman_helper_generic podman-volumes 'volumes' volume ls --format '{{.Name}}'
|
|
||||||
}
|
|
||||||
|
|
||||||
# Combinations. This one seen in diff & inspect
|
|
||||||
_podman_helper_container-or-image() {
|
|
||||||
_podman_helper_image
|
|
||||||
_podman_helper_container
|
|
||||||
}
|
|
||||||
|
|
||||||
# Seen in generate-kube
|
|
||||||
_podman_helper_container-or-pod() {
|
|
||||||
_podman_helper_container
|
|
||||||
_podman_helper_pod
|
|
||||||
}
|
|
||||||
|
|
||||||
# For top and pod-top
|
|
||||||
_podman_helper_format-descriptors() {
|
|
||||||
__podman_helper_generic top-format-descriptors 'format descriptors' \
|
|
||||||
top --list-descriptors
|
|
||||||
}
|
|
||||||
|
|
||||||
# for push, login/logout, and trust
|
|
||||||
# FIXME: some day, use this to define a helper for IMAGE-PATH (in 'pull')
|
|
||||||
_podman_helper_registry() {
|
|
||||||
local expl
|
|
||||||
local -a registries
|
|
||||||
|
|
||||||
# Suggestions for improvement more than welcome.
|
|
||||||
python3 -c 'from configparser import ConfigParser;cp=ConfigParser();cp.read("/etc/containers/registries.conf");registries=eval(cp.get("registries.search","registries"));[print(r) for r in registries]' 2>/dev/null | while read line; do
|
|
||||||
registries+=($line)
|
|
||||||
done
|
|
||||||
|
|
||||||
if (( $#registries )); then
|
|
||||||
_wanted podman-registry expl "registry" compadd ${(u)registries}
|
|
||||||
else
|
|
||||||
_hosts
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# END helpers for command-line args
|
|
||||||
###############################################################################
|
|
||||||
# BEGIN figure out completion helpers for a given (sub)command
|
|
||||||
|
|
||||||
# Read Usage string for this subcommand, set up helpers for its subargs
|
|
||||||
_set_up_podman_args() {
|
|
||||||
_read_podman_usage "$@"
|
|
||||||
|
|
||||||
typeset -ga _podman_args=()
|
|
||||||
# E.g. 'podman exec [options] CONTAINER [...' -> 'CONTAINER [....'
|
|
||||||
local usage_rhs=$(expr "$_podman_usage" : ".*\[options\] \+\(.*\)")
|
|
||||||
|
|
||||||
# e.g. podman pod ps which takes no further args
|
|
||||||
if [ -z "$usage_rhs" ]; then
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# podman diff & inspect accept 'CONTAINER | IMAGE'; make into one keyword.
|
while IFS='\n' read -r comp; do
|
||||||
usage_rhs=${usage_rhs// | /-OR-}
|
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//:/\\:}
|
||||||
|
|
||||||
# Arg parsing. There are three possibilities in Usage messages:
|
local tab=$(printf '\t')
|
||||||
#
|
comp=${comp//$tab/:}
|
||||||
# [IMAGE] - optional image arg (zero or one)
|
|
||||||
# IMAGE - exactly one image arg
|
|
||||||
# IMAGE [IMAGE...] - one or more image args
|
|
||||||
# and, theoretically:
|
|
||||||
# [IMAGE...] - zero or more? Haven't seen it in practice. Defer.
|
|
||||||
#
|
|
||||||
# For completion purposes, we only need to provide two options:
|
|
||||||
# one, or more than one? That is: continue offering completion
|
|
||||||
# suggestions after the first one? For that, we make two passes;
|
|
||||||
# in the first, mark an option as either '' (only one) or
|
|
||||||
|
|
||||||
# Parse each command-line arg seen in usage message
|
__podman_debug "Adding completion: ${comp}"
|
||||||
local word
|
completions+=${comp}
|
||||||
local -A _seen=()
|
lastComp=$comp
|
||||||
for word in ${=usage_rhs}; do
|
|
||||||
local unbracketed=$(expr "$word" : "\[\(.*\)\]")
|
|
||||||
|
|
||||||
if [ -n "$unbracketed" ]; then
|
|
||||||
# Remove all dots; assume(!?) that they'll all be at the end
|
|
||||||
unbracketed=${unbracketed//./}
|
|
||||||
|
|
||||||
if (( $_seen[$unbracketed] )); then
|
|
||||||
# Is this the same word as the previous arg?
|
|
||||||
if expr "$_podman_args[-1]" : ":$unbracketed:" >/dev/null; then
|
|
||||||
# Yes. Make it '*:...' instead of ':...', indicating >1
|
|
||||||
_podman_args[-1]="*$_podman_args[-1]"
|
|
||||||
fi
|
fi
|
||||||
continue
|
done < <(printf "%s\n" "${out[@]}")
|
||||||
|
|
||||||
|
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
||||||
|
__podman_debug "Activating nospace."
|
||||||
|
noSpace="-S ''"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
word=$unbracketed
|
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
|
fi
|
||||||
|
filteringCmd+=" -g $filter"
|
||||||
# As of 2019-03 all such instances are '[COMMAND [ARG...]]' and are,
|
|
||||||
# of course, at the end of the line. We can't offer completion for
|
|
||||||
# these, because the container will have different commands than
|
|
||||||
# the host system... but try anyway.
|
|
||||||
if [ "$word" = '[COMMAND' ]; then
|
|
||||||
# e.g. podman create, exec, run
|
|
||||||
_podman_args+=(
|
|
||||||
":command: _command_names -e"
|
|
||||||
"*::arguments: _normal"
|
|
||||||
)
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Look for an existing helper, e.g. IMAGE -> _podman_helper_image
|
|
||||||
local helper="_podman_helper_${(L)word}"
|
|
||||||
if (( $+functions[$helper] )); then
|
|
||||||
:
|
|
||||||
else
|
|
||||||
# No defined helper. Reset, but check for known expressions.
|
|
||||||
helper=
|
|
||||||
case "$word" in
|
|
||||||
KUBEFILE) helper='_files -g "*.y(|a)ml(-.)"' ;;
|
|
||||||
PATH) helper='_files' ;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Another special case: 'top' actually takes multiple options
|
|
||||||
local multi=
|
|
||||||
if [ "$word" = "FORMAT-DESCRIPTORS" ]; then
|
|
||||||
multi='*'
|
|
||||||
fi
|
|
||||||
_podman_args+=("$multi:${(L)word}:$helper")
|
|
||||||
_seen[$word]=1
|
|
||||||
done
|
done
|
||||||
}
|
filteringCmd+=" ${flagPrefix}"
|
||||||
|
|
||||||
# For an endpoint command, i.e. not a subcommand.
|
__podman_debug "File filtering command: $filteringCmd"
|
||||||
_podman_terminus() {
|
_arguments '*:filename:'"$filteringCmd"
|
||||||
typeset -A opt_args
|
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
||||||
typeset -ga _podman_option_list
|
# File completion for directories only
|
||||||
typeset -ga _podman_args
|
local subDir
|
||||||
integer ret=1
|
subdir="${completions[1]}"
|
||||||
|
if [ -n "$subdir" ]; then
|
||||||
# Find out what args it takes (e.g. image(s), container(s)) and see
|
__podman_debug "Listing directories in $subdir"
|
||||||
# if we have helpers for them.
|
pushd "${subdir}" >/dev/null 2>&1
|
||||||
_set_up_podman_args "$@"
|
|
||||||
_arguments -C $_podman_option_list $_podman_args && ret=0
|
|
||||||
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
# END figure out completion helpers for a given (sub)command
|
|
||||||
################################################################################
|
|
||||||
# BEGIN actual entry point
|
|
||||||
|
|
||||||
# This is the main entry point; it's also where we (recursively) come in
|
|
||||||
# to handle nested subcommands such as 'podman container' or even 3-level
|
|
||||||
# ones like 'podman generate kube'. Nesting is complicated, so here's
|
|
||||||
# my best understanding as of 2019-03-12:
|
|
||||||
#
|
|
||||||
# Easy first: when you do "podman <TAB>" zsh calls us, we run 'podman --help',
|
|
||||||
# figure out the global options and subcommands, and run the magic _arguments
|
|
||||||
# command. That will offer those options/subcommands, and complete, etc.
|
|
||||||
#
|
|
||||||
# Where it gets harder is when you do "podman container mount <TAB>".
|
|
||||||
# zsh first calls us with words=(podman container mount) but we don't
|
|
||||||
# want all that full context yet! We want to go a piece at a time,
|
|
||||||
# handling 'container' first, then 'mount'; ending up with our
|
|
||||||
# final 'podman container mount --help' giving us suitable options
|
|
||||||
# and no subcommands; from which we determine that it's a terminus
|
|
||||||
# and jump to a function that handles non-subcommand arguments.
|
|
||||||
#
|
|
||||||
# This is the closest I've yet come to understanding zsh completion;
|
|
||||||
# it is still incomplete and may in fact be incorrect. But it works
|
|
||||||
# better than anything I've played with so far.
|
|
||||||
_podman_subcommand() {
|
|
||||||
local curcontext="$curcontext" state line
|
|
||||||
typeset -A opt_args
|
|
||||||
integer ret=1
|
|
||||||
|
|
||||||
# Run 'podman --help' / 'podman system --help' for our context (initially
|
|
||||||
# empty, then possibly under subcommands); from those, get a list of
|
|
||||||
# options appropriate for this context and, if applicable, subcommands.
|
|
||||||
_read_podman_options "$@"
|
|
||||||
_read_podman_commands "$@"
|
|
||||||
|
|
||||||
# Now, is this a sub-subcommand, or does it have args?
|
|
||||||
if (( $#_podman_commands )); then
|
|
||||||
# Subcommands required (podman, podman system, etc)
|
|
||||||
local cmd=${words// /_}
|
|
||||||
_arguments -C $_podman_option_list \
|
|
||||||
"(-): :->command" \
|
|
||||||
"(-)*:: :->option-or-argument" \
|
|
||||||
&& ret=0
|
|
||||||
|
|
||||||
case $state in
|
|
||||||
(command)
|
|
||||||
_describe -t command "podman $* command" _podman_commands && ret=0
|
|
||||||
;;
|
|
||||||
(option-or-argument)
|
|
||||||
# I think this is when we have a _completed_ subcommand.
|
|
||||||
# Recurse back into here, offering options for that subcommand.
|
|
||||||
curcontext=${curcontext%:*:*}:podman-${words[1]}:
|
|
||||||
_podman_subcommand "$@" ${words[1]} && ret=0
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
else
|
else
|
||||||
# At a terminus, i.e. podman info, podman history; find out
|
__podman_debug "Listing directories in ."
|
||||||
# what args it takes.
|
|
||||||
_podman_terminus "$@" && ret=0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return ret
|
local result
|
||||||
|
_arguments '*:dirname:_files -/'" ${flagPrefix}"
|
||||||
|
result=$?
|
||||||
|
if [ -n "$subdir" ]; then
|
||||||
|
popd >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
return $result
|
||||||
|
else
|
||||||
|
__podman_debug "Calling _describe"
|
||||||
|
if eval _describe "completions" completions $flagPrefix $noSpace; then
|
||||||
|
__podman_debug "_describe found some completions"
|
||||||
|
|
||||||
|
# Return the success of having called _describe
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
__podman_debug "_describe did not find completions."
|
||||||
|
__podman_debug "Checking if we should do file completion."
|
||||||
|
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
||||||
|
__podman_debug "deactivating file completion"
|
||||||
|
|
||||||
|
# We must return an error code here to let zsh know that there were no
|
||||||
|
# completions found by _describe; this is what will trigger other
|
||||||
|
# matching algorithms to attempt to find completions.
|
||||||
|
# For example zsh can match letters in the middle of words.
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
# Perform file completion
|
||||||
|
__podman_debug "Activating file completion"
|
||||||
|
|
||||||
|
# We must return the result of this command, so it must be the
|
||||||
|
# last command, or else we must store its result to return it.
|
||||||
|
_arguments '*:filename:_files'" ${flagPrefix}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_podman() {
|
# don't run the completion function when being source-ed or eval-ed
|
||||||
_podman_subcommand
|
if [ "$funcstack[1]" = "_podman" ]; then
|
||||||
}
|
_podman
|
||||||
|
fi
|
||||||
|
|
||||||
# Local Variables:
|
# This file is generated with "podman completion"; see: podman-completion(1)
|
||||||
# mode: shell-script
|
|
||||||
# sh-indentation: 4
|
|
||||||
# indent-tabs-mode: nil
|
|
||||||
# sh-basic-offset: 4
|
|
||||||
# End:
|
|
||||||
# vim: ft=zsh sw=4 ts=4 et
|
|
||||||
|
181
completions/zsh/_podman-remote
Normal file
181
completions/zsh/_podman-remote
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
#compdef _podman-remote podman-remote
|
||||||
|
|
||||||
|
# zsh completion for podman-remote -*- shell-script -*-
|
||||||
|
|
||||||
|
__podman-remote_debug()
|
||||||
|
{
|
||||||
|
local file="$BASH_COMP_DEBUG_FILE"
|
||||||
|
if [[ -n ${file} ]]; then
|
||||||
|
echo "$*" >> "${file}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_podman-remote()
|
||||||
|
{
|
||||||
|
local shellCompDirectiveError=1
|
||||||
|
local shellCompDirectiveNoSpace=2
|
||||||
|
local shellCompDirectiveNoFileComp=4
|
||||||
|
local shellCompDirectiveFilterFileExt=8
|
||||||
|
local shellCompDirectiveFilterDirs=16
|
||||||
|
local shellCompDirectiveLegacyCustomComp=32
|
||||||
|
local shellCompDirectiveLegacyCustomArgsComp=64
|
||||||
|
|
||||||
|
local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace
|
||||||
|
local -a completions
|
||||||
|
|
||||||
|
__podman-remote_debug "\n========= starting completion logic =========="
|
||||||
|
__podman-remote_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-remote_debug "Truncated words[*]: ${words[*]},"
|
||||||
|
|
||||||
|
lastParam=${words[-1]}
|
||||||
|
lastChar=${lastParam[-1]}
|
||||||
|
__podman-remote_debug "lastParam: ${lastParam}, lastChar: ${lastChar}"
|
||||||
|
|
||||||
|
# For zsh, when completing a flag with an = (e.g., podman-remote -n=<TAB>)
|
||||||
|
# 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-remote_debug "Adding extra empty parameter"
|
||||||
|
requestComp="${requestComp} \"\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
__podman-remote_debug "About to call: eval ${requestComp}"
|
||||||
|
|
||||||
|
# Use eval to handle any environment variables and such
|
||||||
|
out=$(eval ${requestComp} 2>/dev/null)
|
||||||
|
__podman-remote_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-remote_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-remote_debug "No directive found. Setting do default"
|
||||||
|
directive=0
|
||||||
|
fi
|
||||||
|
|
||||||
|
__podman-remote_debug "directive: ${directive}"
|
||||||
|
__podman-remote_debug "completions: ${out}"
|
||||||
|
__podman-remote_debug "flagPrefix: ${flagPrefix}"
|
||||||
|
|
||||||
|
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
||||||
|
__podman-remote_debug "Completion received error. Ignoring completions."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
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/:}
|
||||||
|
|
||||||
|
__podman-remote_debug "Adding completion: ${comp}"
|
||||||
|
completions+=${comp}
|
||||||
|
lastComp=$comp
|
||||||
|
fi
|
||||||
|
done < <(printf "%s\n" "${out[@]}")
|
||||||
|
|
||||||
|
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
||||||
|
__podman-remote_debug "Activating nospace."
|
||||||
|
noSpace="-S ''"
|
||||||
|
fi
|
||||||
|
|
||||||
|
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-remote_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-remote_debug "Listing directories in $subdir"
|
||||||
|
pushd "${subdir}" >/dev/null 2>&1
|
||||||
|
else
|
||||||
|
__podman-remote_debug "Listing directories in ."
|
||||||
|
fi
|
||||||
|
|
||||||
|
local result
|
||||||
|
_arguments '*:dirname:_files -/'" ${flagPrefix}"
|
||||||
|
result=$?
|
||||||
|
if [ -n "$subdir" ]; then
|
||||||
|
popd >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
return $result
|
||||||
|
else
|
||||||
|
__podman-remote_debug "Calling _describe"
|
||||||
|
if eval _describe "completions" completions $flagPrefix $noSpace; then
|
||||||
|
__podman-remote_debug "_describe found some completions"
|
||||||
|
|
||||||
|
# Return the success of having called _describe
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
__podman-remote_debug "_describe did not find completions."
|
||||||
|
__podman-remote_debug "Checking if we should do file completion."
|
||||||
|
if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
|
||||||
|
__podman-remote_debug "deactivating file completion"
|
||||||
|
|
||||||
|
# We must return an error code here to let zsh know that there were no
|
||||||
|
# completions found by _describe; this is what will trigger other
|
||||||
|
# matching algorithms to attempt to find completions.
|
||||||
|
# For example zsh can match letters in the middle of words.
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
# Perform file completion
|
||||||
|
__podman-remote_debug "Activating file completion"
|
||||||
|
|
||||||
|
# We must return the result of this command, so it must be the
|
||||||
|
# last command, or else we must store its result to return it.
|
||||||
|
_arguments '*:filename:_files'" ${flagPrefix}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# don't run the completion function when being source-ed or eval-ed
|
||||||
|
if [ "$funcstack[1]" = "_podman-remote" ]; then
|
||||||
|
_podman-remote
|
||||||
|
fi
|
||||||
|
|
||||||
|
# This file is generated with "podman-remote completion"; see: podman-completion(1)
|
@ -499,6 +499,7 @@ export GOPATH=%{buildroot}/%{gopath}:$(pwd)/vendor:%{gopath}
|
|||||||
%{_bindir}/%{name}
|
%{_bindir}/%{name}
|
||||||
%{_datadir}/bash-completion/completions/*
|
%{_datadir}/bash-completion/completions/*
|
||||||
%{_datadir}/zsh/site-functions/*
|
%{_datadir}/zsh/site-functions/*
|
||||||
|
%{_datadir}/fish/vendor_completions.d/*
|
||||||
%{_libexecdir}/%{name}/conmon
|
%{_libexecdir}/%{name}/conmon
|
||||||
%config(noreplace) %{_sysconfdir}/cni/net.d/87-%{name}-bridge.conflist
|
%config(noreplace) %{_sysconfdir}/cni/net.d/87-%{name}-bridge.conflist
|
||||||
%{_unitdir}/podman-auto-update.service
|
%{_unitdir}/podman-auto-update.service
|
||||||
|
@ -11,14 +11,14 @@ The completion command allows you to generate shell completion scripts. Supporte
|
|||||||
|
|
||||||
These script are used by the shell to provide suggestions and complete commands when you are typing the command and press [TAB].
|
These script are used by the shell to provide suggestions and complete commands when you are typing the command and press [TAB].
|
||||||
|
|
||||||
Usually these scripts are automatically installed via rpm/deb packages.
|
Usually these scripts are automatically installed via the package manager.
|
||||||
|
|
||||||
## OPTIONS
|
## OPTIONS
|
||||||
**--file**, **-f**
|
#### **--file**, **-f**
|
||||||
|
|
||||||
Write the generated output to file.
|
Write the generated output to file.
|
||||||
|
|
||||||
**--no-desc**
|
#### **--no-desc**
|
||||||
|
|
||||||
Do not provide description in the completions.
|
Do not provide description in the completions.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user