From 90790cabafe02a9a75ec709e8ae1f0092fdda03b Mon Sep 17 00:00:00 2001 From: Chris Weeks Date: Fri, 10 Aug 2018 16:34:05 +1200 Subject: [PATCH] Add support for bash completion This stand-alone file doesn't impact any part of the build process and is designed to be a convenience for end-users. Closes: #1499 Approved by: jlebon --- completion/rpm-ostree | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 completion/rpm-ostree diff --git a/completion/rpm-ostree b/completion/rpm-ostree new file mode 100644 index 00000000..62518814 --- /dev/null +++ b/completion/rpm-ostree @@ -0,0 +1,73 @@ +#/usr/bin/env bash + +# Copyright (C) 2018 Chris Weeks +# +# 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 2 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 . + +# Purpose: a simple bash completion script for rpm-ostree. + +_rpmostree_get_completion() +{ + local cur prev nexttoprev _rpmostree_firstarg _rpmostree_secondarg _rpmostree_command_first_arg_completions _rpmostree_command_second_arg_completions + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + nexttoprev="${COMP_WORDS[COMP_CWORD-2]}" + case ${prev} in + rpm-ostree) + if [ ${COMP_CWORD} -eq 1 ] + then + if [ -z "${_rpmostree_command_completions:-}" ] + then + declare _rpmostree_command_completions="$(rpm-ostree --help | grep -e '^ ' | grep -v 'rpm-ostree' | sed 's/-h, //' | awk '{print $1}')" + fi + COMPREPLY=( $(compgen -W "${_rpmostree_command_completions}" -- "${cur}") ) + fi + return 0 + ;; + --*) + return 0 + ;; + *) + if [ ${COMP_CWORD} -eq 4 ] + then + return 0 + fi + if [ ${COMP_CWORD} -eq 3 ] + then + _rpmostree_firstarg=$(echo ${nexttoprev} | sed 's/[-=]//g;' ) + _rpmostree_secondarg=$(echo ${prev} | sed 's/[-=]//g;' ) + _rpmostree_command_second_arg_completions=_rpmostree_command_${_rpmostree_firstarg}_${_rpmostree_secondarg}_completions + if [ -z "${!_rpmostree_command_second_arg_completions:-}" ] + then + declare _rpmostree_command_${_rpmostree_firstarg}_${_rpmostree_secondarg}_completions="$(rpm-ostree ${nexttoprev} ${prev} --help | grep -e '^ ' | grep -v -e '--version' -e 'rpm-ostree'| sed 's/-., //' | awk '{print $1}')" + fi + COMPREPLY=( $(compgen -W "${!_rpmostree_command_second_arg_completions}" -- "${cur}") ) + fi + if [ ${COMP_CWORD} -eq 2 ] + then + _rpmostree_firstarg=$(echo ${prev} | sed 's/[-=]//g;' ) + _rpmostree_command_first_arg_completions=_rpmostree_command_${_rpmostree_firstarg}_completions + if [ -z "${!_rpmostree_command_first_arg_completions:-}" ] + then + declare _rpmostree_command_${_rpmostree_firstarg}_completions="$(rpm-ostree ${prev} --help | grep -e '^ ' | grep -v -e '--version' -e 'rpm-ostree'| sed 's/-., //' | awk '{print $1}')" + fi + COMPREPLY=( $(compgen -W "${!_rpmostree_command_first_arg_completions}" -- "${cur}") ) + fi + return 0 + ;; +esac +} + +complete -F _rpmostree_get_completion rpm-ostree