# bash-completion # # Copyright (C) 2016 Andreas Kreuzer # Copyright (C) 2016-2021 Daniel Baumann # # SPDX-License-Identifier: GPL-3.0+ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . _container() { local cur prev cmd opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" if [ ${COMP_CWORD} -gt 0 ] then cmd="${COMP_WORDS[1]}" fi if [ "${prev}" = "--" ] then compopt -o bashdefault COMPREPLY=( $(compgen -c -- $cur) ) return 0 fi case "${cmd}" in auto) opts="-f --force -s --start -t --stop" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; console) case "${prev}" in -n|--name) opts="$(container list -s -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; create|cr) case "${prev}" in -n|--name) opts="$(cd /etc/compute-tools/debconf 2>/dev/null && ls *.cfg */*.cfg 2>/dev/null | sed -e 's|.*/||g' -e 's|.cfg$||g')" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; -s|--script) opts="$(cd /usr/share/compute-tools/scripts && find -maxdepth 1 -not -type d -and -not -name 'default' -and -not -name 'debconf' -and -not -name '*.d' -printf '%P\n' | sort)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name -c --capability -d --drop-capability -s --script -v --verbose -b --bind --bind-ro" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; enter) case "${prev}" in -n|--name) opts="$(container list -s -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; key) opts="-a --add -l --list -r --remove" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; limit) case "${prev}" in -n|--name) opts="$(container list -a -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name --blockio-device-weight --blockio-read-bandwidth -b --blockio-weight --blockio-write-bandwidth -c --cpu-quota --cpu-shares -m --memory-limit -t --tasks-max" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; list|ls) case "${prev}" in -h|--host) opts="true false $(hostname -f 2> /dev/null || hostname)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; -f|--format) opts="cli csv json nwdiag shell sh yaml xml" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-a --all -f --format -h --host -o --other -s --started -t --stopped" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; log) case "${prev}" in -d|--date) opts="$(if ls /var/log/compute-tools/container.log-*.gz > /dev/null 2>&1; then \ zcat /var/log/compute-tools/container.log-*.gz | awk '{ print $1 }' | sort -u; \ fi; \ if [ -e /var/log/compute-tools/container.log ]; \ then \ awk '{ print $1 }' /var/log/compute-tools/container.log | sort -u; \ fi) \ today yesterday" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; -n|--name) opts="$(if ls /var/log/compute-tools/container.log-*.gz > /dev/null 2>&1; then \ zgrep -E '(\-n|\-\-name) ' /var/log/compute-tools/container.log-*.gz | sed -e 's|.*-n ||' -e 's|.*--name ||' -e 's| .*$||' | sort -u; \ fi; \ if [ -e /var/log/compute-tools/container.log ]; \ then \ grep -E '(\-n|\-\-name) ' /var/log/compute-tools/container.log | sed -e 's|.*-n ||' -e 's|.*--name ||' -e 's| .*$||' | sort -u; \ fi)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-d --date -n --name" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; move|mv) case "${prev}" in -o|--old) opts="$(container list -t -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-f --force -n --new -o --old" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; remove|rm) case "${prev}" in -n|--name) opts="$(container list -t -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name -f --force" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; restart|rt) case "${prev}" in -n|--name) opts="$(container list -s -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; start|s) case "${prev}" in -n|--name) opts="$(container list -t -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name -v --verbose" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; status|st) case "${prev}" in -n|--name) opts="$(container list -t -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; stop|t) case "${prev}" in -n|--name) opts="$(container list -s -f shell)" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; *) opts="-n --name -f --force" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; esac ;; top) opts="-d --delay" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; version|ver) return 0 ;; *) local commands=$(cd /usr/libexec/container 2>/dev/null && find * -type f -print) COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) return 0 ;; esac compopt -o filenames COMPREPLY=( $(compgen -f -- $cur) ) return 0 } complete -F _container container cnt