Add zsh tabcompletion for docker-env

This commit is contained in:
Daniel_I_Am 2022-05-26 16:15:16 +02:00
parent d2f570b4ef
commit 7e60676483

View File

@ -244,6 +244,45 @@ EOS
eval $run_command
}
# Completion for docker-env
compdef _docker-env docker-env
function _docker-env() {
local curcontext="$curcontext" state
_arguments \
"*-p[Publish a containers port(s) to the host]:port:" \
"*-e[Set environment variables]:env:" \
"*-v[Bind mount a volume]:volume:" \
"-w[Working directory inside the container]" \
"(-p -e -v -w)--[Explicitely stop switches and start positional arguments]" \
"(-p -e -v -w --)1:Container image:->image" \
"*:Container CMD:->cmd"
case $state in
image)
# Check if you can find a colon,
# if so strip everything up to that colon from further completion matching
if compset -P -1 '*:'; then
# Get the tags for the current image and use those for completion
local tags=$(docker image ls --filter 'dangling=false' --filter 'reference='"${words[-1]}"'*' --format '{% raw %}{{.Tag}}{% endraw %}' | sed 's/:/\\:/g' | uniq)
# Add tags for autocompletion. If none exist, then show latest
if [ {% raw %}${#tags}{% endraw %} -gt 0 ]; then
compadd $tags
else
compadd "latest"
fi
else
local repositories=($(docker image ls --filter 'dangling=false' --format "{% raw %}{{.Repository}}{% endraw %}" | sed 's/:/\\:/g' | uniq))
compadd -S : $repositories
fi
;;
cmd)
_default
;;
esac
}
function limit_video_size() {
if [ $# -ne 3 ]; then
echo "Usage: limit_video_size <input_file> <output_file> <max_size (MB)>"