Blame | Last modification | View Log | RSS feed
## Authors:# Tomas Halman <thalman@redhat.com>## Copyright (C) 2019 Red Hat## 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 <http://www.gnu.org/licenses/>.### provides autocompletion for authselect command#_authselect_completions(){local COMMANDSlocal commandlocal possibleoptsfunction is_valid_command() {local cmdfor cmd in "${COMMANDS[@]}"; doif [[ "$cmd" = "$1" ]]; thenreturn 0fidonereturn 1}function get_command() {local optif [[ $COMP_CWORD -lt 2 ]] ; thenreturnfifor opt in "${COMP_WORDS[@]:0:$COMP_CWORD}"; doif is_valid_command "$opt"; thenecho "$opt"returnfidone}function get_command_param() {local havecmd=0local len=${#COMP_WORDS[@]}-1if [[ "$command" = "" ]]; thenreturnfihavecmd=0for (( i=0; i<$len; i++ )); doif [[ "$havecmd" = "1" ]] ; thenif [[ "${COMP_WORDS[$i]}" =~ ^[-=] || "${COMP_WORDS[$i-1]}" = "=" ]] ; thencontinuefiecho "${COMP_WORDS[$i]}"returnfiif [[ "${COMP_WORDS[$i]}" = "$command" ]] ; thenhavecmd=1fidone}function get_profile() {case "$command" inselect|show|requirements|test|list-features)get_command_param;;enable-feature|disable-feature)authselect current 2>/dev/null | head -n1 | cut -d" " -f3;;esac}function get_command_keywords() {local profilecase "$command" inselect|requirements|test)profile="$(get_profile)"if [[ "$profile" != "" ]] ; thenauthselect list-features "$profile" 2>/dev/nullfi;;esac}function get_command_options() {if [[ "${COMP_WORDS[$COMP_CWORD]}" =~ ^- ]] ; thencase "$command" inselect)echo "--force --quiet --nobackup --backup=";;apply-changes|disable-feature)echo "--backup=";;enable-feature)echo "--backup= --quiet";;current|backup-list)echo "--raw";;create-profile)echo "--vendor --base-on= --base-on-default" \"--symlink-meta --symlink-nsswitch --symlink-pam" \"--symlink-dconf --symlink=";;test)echo "--all --nsswitch --system-auth --password-auth" \"--smartcard-auth --fingerprint-auth --postlogin" \"--dconf-db --dconf-lock";;esacfi}function get_global_options() {if [[ "${COMP_WORDS[$COMP_CWORD]}" =~ ^- ]] ; thenecho "--debug --trace --warn --help"fi}function get_option_params() {local optif [[ $COMP_CWORD -gt 2 && "${COMP_WORDS[$COMP_CWORD-1]}" = "=" ]] ; thenopt="${COMP_WORDS[$COMP_CWORD-2]}"elseif [[ $COMP_CWORD -gt 1 ]] ; thenopt="${COMP_WORDS[$COMP_CWORD-1]}"fificase "$opt" in--base-on)authselect list 2>/dev/null | cut -d" " -f2;;--symlink)echo "dconf-db dconf-locks fingerprint-auth nsswitch.conf" \"password-auth postlogin smartcard-auth system-auth" \"README REQUIREMENTS";;esac}function get_command_params() {local ilocal profileif [[ "$command" = "" ]]; thenreturnfifor (( i=$COMP_CWORD-1; i>1; i-- )); doopt="${COMP_WORDS[$i]}"if [[ "$opt" = "$command" ]] ; thenbreakfiif [[ "$opt" =~ ^[-=] || "${COMP_WORDS[$i-1]}" = "=" ]] ; thencontinuefireturndonecase "$command" inselect|show|requirements|test|list-features)authselect list 2>/dev/null | cut -d" " -f2;;backup-remove|backup-restore)authselect backup-list 2>/dev/null | cut -d" " -f1;;enable-feature|disable-feature)profile="$(get_profile)"if [[ "$profile" != "" ]] ; thenauthselect list-features "$profile" 2>/dev/nullfi;;esac}COMMANDS=(select apply-changes list list-features show requirements currentcheck test enable-feature disable-feature create-profilebackup-list backup-remove backup-restore)possibleopts="$(get_option_params)"if [[ "$possibleopts" != "" ]]; thenif [[ "${COMP_WORDS[$COMP_CWORD]}" = "=" ]]; thenCOMPREPLY=($(compgen -W "$possibleopts"))elseCOMPREPLY=($(compgen -W "$possibleopts" -- "${COMP_WORDS[$COMP_CWORD]}"))fielsecommand="$(get_command)"if [[ "$command" = "" ]]; thenpossibleopts="$(get_global_options) ${COMMANDS[@]}"elsepossibleopts="$(get_global_options) $(get_command_params) $(get_command_keywords) $(get_command_options)"fiCOMPREPLY=($(compgen -W "$possibleopts" -- "${COMP_WORDS[$COMP_CWORD]}"))fi}complete -F _authselect_completions authselect