bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Tue, 11 May 2021 18:30:50 +0200
branchv_0
changeset 24 c69670b7b4ef
child 25 98be80d2e65b
permissions -rw-r--r--
new CLI interface: --relation, --attribute, --pattern
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info)
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
# it under the terms of the GNU General Public License as published by
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_tr_grep_completion() {
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	if   [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("'.*'")
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
	elif [[ "$w1" == "--attribute"                     && "x$w0" == "x" ]];    then COMPREPLY=("'.*'")
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	elif [[ "$w1" == "--pattern"                       && "x$w0" == "x" ]];    then COMPREPLY=("''")
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	else
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
		OPTIONS=(
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
			"--relation"
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
			"--attribute"
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
			"--pattern"
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		)
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	fi
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
}
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
c69670b7b4ef new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
complete -F _relpipe_tr_grep_completion relpipe-tr-grep