bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sat, 26 Oct 2019 23:01:03 +0200
branchv_0
changeset 25 3f47b43e528d
child 27 532953173cd5
permissions -rw-r--r--
bash-completion script
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
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_in_filesystem_completion() {
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	FILE_FIELDS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"path"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"name"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		"size"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		"path_absolute"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
		"path_canonical"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		"type"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		"symlink_target_type"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		"symlink_target"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
		"owner"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		"group"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		"content"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	XATTR_FIELDS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		"mime_type"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		"charset"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		"creator"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		"xdg.comment"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		"xdg.origin.url"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		"xdg.origin.email.subject"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		"xdg.language"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		"xdg.publisher"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		"dublincore.title"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		"dublincore.creator"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		"dublincore.rights"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	elif [[ "$w1" == "--as"            && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	elif [[ "$w1" == "--option"        && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	elif [[ "$w2" == "--option"        && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
	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
    59
	elif [[ "$w1" == "--xattr"                          ]];    then COMPREPLY=($(compgen -W "${XATTR_FIELDS[*]}" -- "$w0"))
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	else
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
		OPTIONS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
			"--relation"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
			"--file"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
			"--xattr"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
			"--as"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
			"--option"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		)
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	fi
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
complete -F _relpipe_in_filesystem_completion relpipe-in-filesystem