bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sat, 28 Nov 2020 21:15:51 +0100
branchv_0
changeset 30 8c3fe9af6066
parent 24 07e0a2edf3bc
child 31 bdf04cd91308
permissions -rw-r--r--
bash-completion: add unescaping options
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=(
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    33
		"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
    34
		"allow-sections"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    35
		"allow-section-tags"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    36
		"allow-sub-keys"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    37
		"comment-separators"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    38
		"key-value-separators"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    39
		"quotes"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    40
		"dialect"
30
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    41
		"unescape-basic"
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    42
		"unescape-java-properties"
8c3fe9af6066 bash-completion: add unescaping options
František Kučera <franta-hg@frantovo.cz>
parents: 24
diff changeset
    43
		"unescape-backspace"
23
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    44
	);
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    45
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    46
	DIALECTS=(
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    47
		"java-properties"
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    48
	);
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    49
0
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	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
    51
	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
    52
	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
    53
	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
    54
	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
    55
	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
    56
	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
    57
	elif [[ "$w1" == "--parser-option"                                  ]];    then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0"))
b497140b0b63 enable configuring the parser from CLI: --parser-option
František Kučera <franta-hg@frantovo.cz>
parents: 6
diff changeset
    58
	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
    59
	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
    60
	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
    61
	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
    62
	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
    63
	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
    64
	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
    65
	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
    66
	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
    67
	elif [[ "$w2" == "--parser-option" && "$w1" == "key-value-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
    68
	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
    69
	else
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
		OPTIONS=(
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
			"--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
    72
			"--enable-sections"
5
d70ea23682aa rename subkey to sub_key/sub-key
František Kučera <franta-hg@frantovo.cz>
parents: 2
diff changeset
    73
			"--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
    74
			"--enable-comments"
6
fb717cfbfea1 improved support for comments and whitespace
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    75
			"--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
    76
			"--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
    77
			"--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
    78
			"--parser-option"
0
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
		)
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
	fi
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
}
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
16c7fa9b7c49 project and parser skeleton + output demo data
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
complete -F _relpipe_in_ini_completion relpipe-in-ini