#!/bin/sh # # Copyright (C) 2017-2025 Savoir-faire Linux, Inc. # # 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 . if [ -z "$BASH_VERSION" ]; then _init_completion() { : } _get_first_arg() { : } fi _cqfd() { local cur prev words cword _init_completion || return case $prev in -C|-d|-f) _filedir return ;; -b) local flavors cqfdrc=.cqfdrc # before we scan for flavors, see if a cqfdrc name was # specified with -f for (( i=0; i < ${#words[@]}; i++ )); do if [[ ${words[i]} == -f ]]; then # eval for tilde expansion eval cqfdrc=( "${words[i+1]}" ) fi done if [ -e "$cqfdrc" ]; then flavors=$(cqfd -f $cqfdrc flavors) COMPREPLY=( $(compgen -W "$flavors" -- "$cur") ) fi return ;; init|flavors|release|help) return ;; esac local arg= _get_first_arg if [[ "$arg" =~ ^(exec|run)$ ]]; then for (( i=1; i <= cword; i++ )); do if [[ ${words[i]} == "$arg" ]]; then if [[ $((i+1)) -eq $cword ]]; then break elif [[ ${words[i+1]} == -c ]]; then ((i++)) fi _command_offset $((i + 1)) return fi done if [[ "$arg" == exec ]]; then COMPREPLY=( $(compgen -c -- "$cur") ) else COMPREPLY=( $(compgen -c -W "-c" -- "$cur") ) fi return elif [[ "$arg" =~ ^(shell|sh|ash|dash|bash|ksh|zsh|csh|tcsh|fish)$ ]]; then for (( i=1; i <= cword; i++ )); do if [[ ${words[i]} == "$arg" ]]; then ((i++)) break fi done COMP_WORDS=("${SHELL:-/bin/sh}" "${COMP_WORDS[@]:$i}" "$cur") COMP_LINE="${COMP_WORDS[*]}" COMP_POINT="${#COMP_LINE}" _command_offset 0 return fi local opts="-C -d -f -b -q --release -V --version -h --help" if [[ "$cur" == -* ]]; then COMPREPLY=( $(compgen -W "$opts" -- "$cur") ) return fi local shells="sh ash dash bash ksh zsh csh tcsh fish" local cmds="init flavors exec run release shell version help" COMPREPLY=( $(compgen -W "$shells $cmds $opts" -- "$cur") ) } && complete -F _cqfd cqfd