bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sat, 11 Jan 2020 18:13:30 +0100
branchv_0
changeset 31 c64e1588f428
parent 29 6f15f18d2abf
child 45 f466b4c7d9b1
permissions -rw-r--r--
rename --exec to --streamlet
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
3f47b43e528d 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)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
3f47b43e528d 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
3f47b43e528d 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
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
3f47b43e528d 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,
3f47b43e528d 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
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
3f47b43e528d 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
3f47b43e528d 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/>.
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
28
9172bd97ae99 custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    16
_relpipe_in_filesystem_scripts() {
9172bd97ae99 custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    17
	while read c; do echo ${c:31}; done < <(compgen -c "__relpipe_in_filesystem_script_");
9172bd97ae99 custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    18
}
9172bd97ae99 custom scripts for additional attributes
František Kučera <franta-hg@frantovo.cz>
parents: 27
diff changeset
    19
25
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
_relpipe_in_filesystem_completion() {
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	local w0 w1 w2
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	COMPREPLY=()
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
	w0=${COMP_WORDS[COMP_CWORD]}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	w1=${COMP_WORDS[COMP_CWORD-1]}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	w2=${COMP_WORDS[COMP_CWORD-2]}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	FILE_FIELDS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
		"path"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		"name"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		"size"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		"path_absolute"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		"path_canonical"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		"type"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		"symlink_target_type"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		"symlink_target"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		"owner"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		"group"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		"content"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	XATTR_FIELDS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		"mime_type"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		"charset"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		"creator"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		"xdg.comment"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		"xdg.origin.url"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		"xdg.origin.email.subject"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		"xdg.language"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		"xdg.publisher"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		"dublincore.title"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		"dublincore.creator"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		"dublincore.rights"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	elif [[ "$w1" == "--as"            && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	elif [[ "$w1" == "--option"        && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	elif [[ "$w2" == "--option"        && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	elif [[ "$w1" == "--file"                           ]];    then COMPREPLY=($(compgen -W "${FILE_FIELDS[*]}"  -- "$w0"))
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	elif [[ "$w1" == "--xattr"                          ]];    then COMPREPLY=($(compgen -W "${XATTR_FIELDS[*]}" -- "$w0"))
31
c64e1588f428 rename --exec to --streamlet
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    63
	elif [[ "$w1" == "--streamlet"                      ]];    then COMPREPLY=($(compgen -W "$(_relpipe_in_filesystem_scripts)" -- "$w0"))
25
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	else
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		OPTIONS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
			"--relation"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
			"--file"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
			"--xattr"
31
c64e1588f428 rename --exec to --streamlet
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    69
			"--streamlet"
25
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
			"--as"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
			"--option"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	fi
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
complete -F _relpipe_in_filesystem_completion relpipe-in-filesystem