bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Fri, 26 Aug 2022 22:41:46 +0200
branchv_0
changeset 39 509e4b02f3c2
parent 34 7eb3dcacba7b
permissions -rw-r--r--
fix typo: enbaled → enabled (thanks Jiří Wolker for reporting)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
16c7fa9b7c49 project and parser skeleton + output demo data
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
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_in_ini_completion() {
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    25
	BOOLEAN_VALUES=(
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    26
		"true"
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    27
		"false"
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    28
	)
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    29
30
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    30
	# TODO: introspection: after moving to alt2xml the available options and their values should be provided by the parser
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    31
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    32
	PARSER_OPTIONS=(
34
7eb3dcacba7b implement --parser-option allow-line-continuation-with-escaping + add skeleton for allow-line-continuation-with-space
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    33
		"allow-line-continuation-with-escaping"
7eb3dcacba7b implement --parser-option allow-line-continuation-with-escaping + add skeleton for allow-line-continuation-with-space
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    34
		"allow-line-continuation-with-space"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    35
		"trim-continuing-lines"
24
07e0a2edf3bc add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    36
		"allow-sections"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    37
		"allow-section-tags"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    38
		"allow-sub-keys"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    39
		"comment-separators"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    40
		"key-value-separators"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    41
		"quotes"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    42
		"dialect"
30
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    43
		"unescape-basic"
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    44
		"unescape-java-properties"
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    45
		"unescape-backspace"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    46
	);
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    47
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    48
	DIALECTS=(
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    49
		"java-properties"
33
3b81fbeb5f3b java-manifest-mf + improve unescaping
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
    50
		"java-manifest-mf"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    51
	);
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    52
0
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	if   [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("''")
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    54
	elif [[ "$w1" == "--enable-sections"                                ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
5
d70ea23682aa rename subkey to sub_key/sub-key
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    55
	elif [[ "$w1" == "--enable-sub-keys"                                ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    56
	elif [[ "$w1" == "--enable-comments"                                ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
6
fb717cfbfea1 improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    57
	elif [[ "$w1" == "--enable-whitespace"                              ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    58
	elif [[ "$w1" == "--enable-line-numbers"                            ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    59
	elif [[ "$w1" == "--enable-event-numbers"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    60
	elif [[ "$w1" == "--parser-option"                                  ]];    then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0"))
34
7eb3dcacba7b implement --parser-option allow-line-continuation-with-escaping + add skeleton for allow-line-continuation-with-space
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    61
	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-line-continuation-with-escaping"    ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
7eb3dcacba7b implement --parser-option allow-line-continuation-with-escaping + add skeleton for allow-line-continuation-with-space
František Kučera <franta-hg@frantovo.cz>
parents: 33
diff changeset
    62
	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-line-continuation-with-space"       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    63
	elif [[ "$w2" == "--parser-option" && "$w1" == "trim-continuing-lines"                    ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
24
07e0a2edf3bc add --parser-option allow-sections (Java .properties have no sections)
František Kučera <franta-hg@frantovo.cz>
parents: 23
diff changeset
    64
	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-sections"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    65
	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-section-tags"                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    66
	elif [[ "$w2" == "--parser-option" && "$w1" == "allow-sub-keys"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
30
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    67
	elif [[ "$w2" == "--parser-option" && "$w1" == "unescape-basic"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    68
	elif [[ "$w2" == "--parser-option" && "$w1" == "unescape-java-properties"                 ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    69
	elif [[ "$w2" == "--parser-option" && "$w1" == "unescape-backspace"                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    70
	elif [[ "$w2" == "--parser-option" && "$w1" == "dialect"                                  ]];    then COMPREPLY=($(compgen -W "${DIALECTS[*]}" -- "$w0"))
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    71
	elif [[ "$w2" == "--parser-option" && "$w1" == "comment-separators"      && "x$w0" == "x" ]];    then COMPREPLY=("'#;'")
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    72
	elif [[ "$w2" == "--parser-option" && "$w1" == "key-value-separators"    && "x$w0" == "x" ]];    then COMPREPLY=("'=:'")
31
bdf04cd91308 bash-completion: fix quotes
František Kučera <franta-hg@frantovo.cz>
parents: 30
diff changeset
    73
	elif [[ "$w2" == "--parser-option" && "$w1" == "quotes"                  && "x$w0" == "x" ]];    then COMPREPLY=("\$'\"\\''")
0
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	else
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
		OPTIONS=(
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
			"--relation"
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    77
			"--enable-sections"
5
d70ea23682aa rename subkey to sub_key/sub-key
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    78
			"--enable-sub-keys"
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    79
			"--enable-comments"
6
fb717cfbfea1 improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    80
			"--enable-whitespace"
2
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    81
			"--enable-line-numbers"
f031a4dc7c52 add options: --enable-sections --enable-subkeys --enable-comments --enable-line-numbers --enable-event-numbers
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    82
			"--enable-event-numbers"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    83
			"--parser-option"
0
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		)
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
	fi
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
}
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
complete -F _relpipe_in_ini_completion relpipe-in-ini