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