bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Tue, 11 May 2021 23:23:35 +0200
branchv_0
changeset 43 5d369d33a027
parent 37 0c050899c77f
permissions -rw-r--r--
fix bash-completion example condition
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
3bcb28cbf655 bash-completion script
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
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_tr_awk_completion() {
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
	DATA_TYPE=(
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
		"string"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"integer"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"boolean"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	)
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
	if   [[ "$w1" == "--relation"          && "x$w0" == "x" ]];    then COMPREPLY=("'.*'")
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	elif [[ "$w1" == "--before-records"    && "x$w0" == "x" ]];    then COMPREPLY=("''")
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	elif [[ "$w1" == "--after-records"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	elif [[ "$w1" == "--output-attribute"  && "x$w0" == "x" ]];    then COMPREPLY=("''")
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	elif [[ "$w2" == "--output-attribute"                   ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	elif [[ "$w1" == "--define"            && "x$w0" == "x" ]];    then COMPREPLY=("''")
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	elif [[ "$w2" == "--define"                             ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	elif [[ "$w3" == "--define"            && "x$w0" == "x" ]];    then COMPREPLY=("''")
37
0c050899c77f add --where option: similar to --for-each but better expresses the intention: filtering
František Kučera <franta-hg@frantovo.cz>
parents: 36
diff changeset
    38
	elif [[ "$w1" == "--for-each"          && "x$w0" == "x" ]];    then COMPREPLY=("'(a == \"abc\") { a = \"X\"; record(); }'")
43
5d369d33a027 fix bash-completion example condition
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
    39
	elif [[ "$w1" == "--where"             && "x$w0" == "x" ]];    then COMPREPLY=("'a == \"abc\" || b == 123'")
36
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	else
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		OPTIONS=(
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
			"--relation"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
			"--output-attribute"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
			"--input-attributes-append"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
			"--input-attributes-prepend"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
			"--debug-variable-mapping"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
			"--before-records"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
			"--after-records"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
			"--for-each"
37
0c050899c77f add --where option: similar to --for-each but better expresses the intention: filtering
František Kučera <franta-hg@frantovo.cz>
parents: 36
diff changeset
    50
			"--where"
36
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
			"--drop"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
			"--define"
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		)
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	fi
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
}
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
complete -F _relpipe_tr_awk_completion relpipe-tr-awk
3bcb28cbf655 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
complete -F _relpipe_tr_awk_completion relpipe-in-awk