bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sat, 12 Dec 2020 19:52:38 +0100
branchv_0
changeset 5 bee7acb57330
parent 4 372b161669e4
child 8 7c85dc9a310b
permissions -rw-r--r--
implement --writer-option allow-sections false (flat key=value output)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
1bb084f84eb9 project skeleton
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
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_out_ini_completion() {
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	BOOLEAN_VALUES=(
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"true"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"false"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	)
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
	STYLES=(
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		"auto"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		"dropped"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		"literal"
1
e04e5bbc147b add --style section-first
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    34
		"section-first"
0
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		"standard"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	)
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	DIALECTS=(
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		"java-properties"
3
ae8775e0bc7a configurable/modular dialects and escaping
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    40
		"java-manifest-mf"
0
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	);
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
4
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    43
	QUOTING_TYPES=(
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    44
		"none"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    45
		"apostrophes"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    46
		"quotes"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    47
	)
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    48
0
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	WRITER_OPTIONS=(
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		"dialect"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		"comment-separator-for-sections"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		"comment-separator-for-entries"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		"comment-separator-standalone"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		"key-value-separator"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		"escape-backspace"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		"escape-basic"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		"escape-java-properties"
4
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    58
		"quotes-type-for-sections"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    59
		"quotes-type-for-keys"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    60
		"quotes-type-for-values"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    61
		"quotes-pattern-for-sections"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    62
		"quotes-pattern-for-keys"
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    63
		"quotes-pattern-for-values"
5
bee7acb57330 implement --writer-option allow-sections false (flat key=value output)
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    64
		"allow-sections"
bee7acb57330 implement --writer-option allow-sections false (flat key=value output)
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    65
		"hierarchy-separator"
0
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	);
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	if   [[ "$w1" == "--relation"                                            && "x$w0" == "x" ]];    then COMPREPLY=("''")
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
	elif [[ "$w1" == "--style"                                                                ]];    then COMPREPLY=($(compgen -W "${STYLES[*]}" -- "$w0"))
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	elif [[ "$w1" == "--writer-option"                                                        ]];    then COMPREPLY=($(compgen -W "${WRITER_OPTIONS[*]}" -- "$w0"))
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	elif [[ "$w2" == "--writer-option" && "$w1" == "dialect"                                  ]];    then COMPREPLY=($(compgen -W "${DIALECTS[*]}" -- "$w0"))
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	elif [[ "$w2" == "--writer-option" && "$w1" == "comment-separator-for-sections"           ]];    then COMPREPLY=("' ; '")
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	elif [[ "$w2" == "--writer-option" && "$w1" == "comment-separator-for-entries"            ]];    then COMPREPLY=("' ; '")
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	elif [[ "$w2" == "--writer-option" && "$w1" == "comment-separator-standalone"             ]];    then COMPREPLY=("'; '")
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	elif [[ "$w2" == "--writer-option" && "$w1" == "key-value-separator"                      ]];    then COMPREPLY=("' = '")
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	elif [[ "$w2" == "--writer-option" && "$w1" == "escape-backspace"                         ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
	elif [[ "$w2" == "--writer-option" && "$w1" == "escape-basic"                             ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	elif [[ "$w2" == "--writer-option" && "$w1" == "escape-java-properties"                   ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
4
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    80
	elif [[ "$w2" == "--writer-option" && "$w1" == "quotes-type-for-sections"                 ]];    then COMPREPLY=($(compgen -W "${QUOTING_TYPES[*]}" -- "$w0"))
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    81
	elif [[ "$w2" == "--writer-option" && "$w1" == "quotes-type-for-keys"                     ]];    then COMPREPLY=($(compgen -W "${QUOTING_TYPES[*]}" -- "$w0"))
372b161669e4 configurable quoting
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    82
	elif [[ "$w2" == "--writer-option" && "$w1" == "quotes-type-for-values"                   ]];    then COMPREPLY=($(compgen -W "${QUOTING_TYPES[*]}" -- "$w0"))
5
bee7acb57330 implement --writer-option allow-sections false (flat key=value output)
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    83
	elif [[ "$w2" == "--writer-option" && "$w1" == "allow-sections"                           ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
bee7acb57330 implement --writer-option allow-sections false (flat key=value output)
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    84
	elif [[ "$w2" == "--writer-option" && "$w1" == "hierarchy-separator"                      ]];    then COMPREPLY=("'/'")
0
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
	elif [[ "$w2" == "--writer-option"                                       && "x$w0" == "x" ]];    then COMPREPLY=("''")
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
	else
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
		OPTIONS=(
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
			"--writer-option"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
			"--relation"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
			"--style"
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		)
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
	fi
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
}
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
1bb084f84eb9 project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
complete -F _relpipe_out_ini_completion relpipe-out-ini