bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sun, 28 Aug 2022 18:03:13 +0200
branchv_0
changeset 59 a1775ba6d056
parent 55 3a120e64bb37
permissions -rw-r--r--
optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes) examples, shortcuts: relpipe-tr-unionall() { relpipe-tr-sql --copy '.+' --on-duplicate-relation insert; } # does UNION ALL for all tables with same name (including already existing ones – when non-empty database is used) relpipe-tr-unionall() { relpipe-tr-serialize | relpipe-tr-deserialize; } # does UNION ALL only for tables with same name immediately following each other (interleaved duplicates will stay unaffected)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
76cbba3f7041 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)
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
76cbba3f7041 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
76cbba3f7041 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
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
76cbba3f7041 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,
76cbba3f7041 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
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
76cbba3f7041 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
76cbba3f7041 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/>.
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
37
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    16
_relpipe_tr_sql_completion_dsn() {
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    17
	if type relpipe-out-nullbyte &> /dev/null; then
55
3a120e64bb37 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time: bash-completion.sh
František Kučera <franta-hg@frantovo.cz>
parents: 54
diff changeset
    18
		relpipe-tr-sql --list-data-sources true | relpipe-out-nullbyte | while read -r -d '' name; do read -r -d '' description; echo $name; done
37
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    19
	fi
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    20
}
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    21
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
_relpipe_tr_sql_completion() {
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	local w0 w1 w2
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	COMPREPLY=()
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	w0=${COMP_WORDS[COMP_CWORD]}
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
	w1=${COMP_WORDS[COMP_CWORD-1]}
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	w2=${COMP_WORDS[COMP_CWORD-2]}
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
24
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    30
	DATA_TYPE=(
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    31
		"string"
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    32
		"integer"
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    33
		"boolean"
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    34
	)
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
54
bc6e11cccdf4 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time
František Kučera <franta-hg@frantovo.cz>
parents: 47
diff changeset
    36
	BOOLEAN_VALUES=(
bc6e11cccdf4 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time
František Kučera <franta-hg@frantovo.cz>
parents: 47
diff changeset
    37
		"true"
bc6e11cccdf4 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time
František Kučera <franta-hg@frantovo.cz>
parents: 47
diff changeset
    38
		"false"
bc6e11cccdf4 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time
František Kučera <franta-hg@frantovo.cz>
parents: 47
diff changeset
    39
	)
bc6e11cccdf4 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time
František Kučera <franta-hg@frantovo.cz>
parents: 47
diff changeset
    40
59
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    41
	ON_DUPLICATE_RELATION=(
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    42
		"fail"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    43
		"insert"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    44
		# "extend"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    45
		# "drop"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    46
		# "skip"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    47
		# "rename-new"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    48
		# "rename-old"
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    49
	)
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    50
47
428c278af4be rename option --data-source-url to --data-source-string
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
    51
	DATA_SOURCE_STRING=(
37
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    52
		"Driver=SQLite3;Database=file::memory:"
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    53
		"Driver=SQLite3;Database=file:temp-relpipe.sqlite"
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    54
		"Driver=SQLite3;Database=file:/tmp/relpipe.sqlite"
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    55
	)
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    56
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	elif [[ "$w2" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=('"SELECT * FROM "')
24
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    59
	elif [[ "$w1" == "--type-cast"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    60
	elif [[ "$w2" == "--type-cast"                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
54
bc6e11cccdf4 add boolean parameter to --list-data-sources + allow listing and SELECTing at the same time
František Kučera <franta-hg@frantovo.cz>
parents: 47
diff changeset
    61
	elif [[ "$w1" == "--list-data-sources"              ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	elif [[ "$w1" == "--parameter"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
59
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    63
	elif [[ "$w1" == "--on-duplicate-relation"          ]];    then COMPREPLY=($(compgen -W "${ON_DUPLICATE_RELATION[*]}" -- "$w0"))
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	elif [[ "$w1" == "--copy"          && "x$w0" == "x" ]];    then COMPREPLY=("'.+'")
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
	elif [[ "$w1" == "--copy-renamed"  && "x$w0" == "x" ]];    then COMPREPLY=("'.+'")
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	elif [[ "$w2" == "--copy-renamed"  && "x$w0" == "x" ]];    then COMPREPLY=("'copy_of_\$0'")
37
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    67
	elif [[ "$w1" == "--data-source-name"               ]];    then COMPREPLY=($(compgen -W "$(_relpipe_tr_sql_completion_dsn)" -- "$w0"))
47
428c278af4be rename option --data-source-url to --data-source-string
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
    68
	elif [[ "$w1" == "--data-source-string"             ]];    then COMPREPLY=($(compgen -W "${DATA_SOURCE_STRING[*]}" -- "$w0"))
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	else
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		OPTIONS=(
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
			"--relation"
24
884ece10575d add --type-cast to allow explicit specification of type for given output attributes
František Kučera <franta-hg@frantovo.cz>
parents: 18
diff changeset
    72
			"--type-cast"
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
			"--parameter"
59
a1775ba6d056 optional UNION ALL: CLI option '--on-duplicate-relation' with values 'fail' and 'insert' (later more modes)
František Kučera <franta-hg@frantovo.cz>
parents: 55
diff changeset
    74
			"--on-duplicate-relation"
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
			"--copy"
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
			"--copy-renamed"
34
24c05e69d68f add ODBC library and --list-data-sources mode (DSN)
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    77
			"--list-data-sources"
37
3de41719d7eb add options --data-source-name and --data-source-url for custom datasource; drop options --file and --file-keep
František Kučera <franta-hg@frantovo.cz>
parents: 34
diff changeset
    78
			"--data-source-name"
47
428c278af4be rename option --data-source-url to --data-source-string
František Kučera <franta-hg@frantovo.cz>
parents: 37
diff changeset
    79
			"--data-source-string"
18
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
		)
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	fi
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
}
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
complete -F _relpipe_tr_sql_completion relpipe-tr-sql
76cbba3f7041 bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
complete -F _relpipe_tr_sql_completion relpipe-in-sql