bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Tue, 13 Dec 2022 02:07:00 +0100
branchv_0
changeset 3 202ce847990c
parent 0 7727b4d5560d
permissions -rw-r--r--
configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
7727b4d5560d new module: relpipe-out-sql
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
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_out_sql_completion() {
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
3
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    25
	BOOLEAN_VALUES=(
0
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"true"
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"false"
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	)
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
3
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    30
	INSERT_MODES=(
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    31
		"single"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    32
		"multi"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    33
	)
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    34
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    35
	RELPIPE_TYPES=(
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    36
		"boolean"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    37
		"integer"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    38
		"string"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    39
	)
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    40
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    41
	SQL_TYPES=(
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    42
		"text"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    43
		"integer"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    44
		"bigint"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    45
		"numeric"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    46
		"varchar(20)"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    47
		"bit"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    48
		"date"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    49
		"time"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    50
		"timestamp"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    51
	)
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    52
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    53
	  if [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("'.*'")
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    54
	elif [[ "$w1" == "--write-ddl"                                      ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    55
	elif [[ "$w1" == "--write-dml"                                      ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    56
	elif [[ "$w1" == "--write-column-names"                             ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    57
	elif [[ "$w1" == "--insert-mode"                                    ]];    then COMPREPLY=($(compgen -W "${INSERT_MODES[*]}" -- "$w0"))
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    58
	elif [[ "$w1" == "--type-cast"                     && "x$w0" == "x" ]];    then COMPREPLY=("'.*'")
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    59
	elif [[ "$w2" == "--type-cast"                                      ]];    then COMPREPLY=($(compgen -W "${RELPIPE_TYPES[*]}" -- "$w0"))
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    60
	elif [[ "$w3" == "--type-cast"                                      ]];    then COMPREPLY=($(compgen -W "${SQL_TYPES[*]}" -- "$w0"))
0
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	else
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
		OPTIONS=(
3
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    63
			"--relation"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    64
			"--write-ddl"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    65
			"--write-dml"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    66
			"--write-column-names"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    67
			"--insert-mode"
202ce847990c configuration: --write-ddl, --write-dml, --write-column-names, --insert-mode, --type-cast
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    68
			"--type-cast"
0
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		)
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	fi
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
}
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
7727b4d5560d new module: relpipe-out-sql
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
complete -F _relpipe_out_sql_completion relpipe-out-sql