bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Fri, 13 May 2022 21:35:30 +0200
branchv_0
changeset 96 c34106244a54
parent 52 fea625f0a096
permissions -rw-r--r--
portable order of (i++) parameters
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
	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	elif [[ "$w1" == "--as"            && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	elif [[ "$w1" == "--option"        && "x$w0" == "x" ]];    then COMPREPLY=("''")
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	elif [[ "$w2" == "--option"        && "x$w0" == "x" ]];    then COMPREPLY=("''")
52
fea625f0a096 parallel processing: prepare infrastructure
František Kučera <franta-hg@frantovo.cz>
parents: 45
diff changeset
    57
	elif [[ "$w1" == "--parallel"      && "x$w0" == "x" ]];    then COMPREPLY=($(nproc --all))
25
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"))
45
f466b4c7d9b1 streamlets: use $RELPIPE_IN_FILESYSTEM_STREAMLET_PATH variable instead of __relpipe_in_filesystem_script_ prefix
František Kučera <franta-hg@frantovo.cz>
parents: 31
diff changeset
    60
	elif [[ "$w1" == "--streamlet"                      ]];    then COMPREPLY=($(while read c; do PATH="$RELPIPE_IN_FILESYSTEM_STREAMLET_PATH" type -P "$c" &>/dev/null && echo "$c"; done < <(PATH="$RELPIPE_IN_FILESYSTEM_STREAMLET_PATH" compgen -A command -- "$w0")))
25
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	else
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
		OPTIONS=(
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
			"--relation"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
			"--file"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
			"--xattr"
31
c64e1588f428 rename --exec to --streamlet
František Kučera <franta-hg@frantovo.cz>
parents: 29
diff changeset
    66
			"--streamlet"
25
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
			"--as"
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
			"--option"
52
fea625f0a096 parallel processing: prepare infrastructure
František Kučera <franta-hg@frantovo.cz>
parents: 45
diff changeset
    69
			"--parallel"
25
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
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	fi
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
}
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
3f47b43e528d bash-completion script
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
complete -F _relpipe_in_filesystem_completion relpipe-in-filesystem