bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Tue, 06 Oct 2020 16:55:22 +0200
branchv_0
changeset 10 ded44e94147c
parent 8 8ef1980db907
child 11 07247893054e
permissions -rw-r--r--
add --jack-connect-to-port and --required-jack-connections options
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
8ef1980db907 configurable JACK client name
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
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
10
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    16
_relpipe_in_jack_completion_ports() {
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    17
	# TODO: simpler and faster implementation in relpipe-out-jack or relpipe-in-jack C++ code
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    18
	jack_lsp -tp 2>/dev/null \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    19
		| tr -d \\t \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    20
		| tr \\n \\0 \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    21
		| relpipe-in-cli \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    22
			--relation "jack_midi_port" \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    23
			--attribute "name" string \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    24
			--attribute "properties" string \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    25
			--attribute "type" string \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    26
			--records-on-stdin true \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    27
		| relpipe-tr-grep '.*' 'properties' 'output' \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    28
		| relpipe-tr-grep '.*' 'type' 'midi' \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    29
		| relpipe-tr-cut '.*' 'name' \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    30
		| relpipe-out-nullbyte \
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    31
		| tr \\0 \\n
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    32
}
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    33
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
_relpipe_in_jack_completion() {
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	local w0 w1 w2 w3
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	COMPREPLY=()
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	w0=${COMP_WORDS[COMP_CWORD]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	w1=${COMP_WORDS[COMP_CWORD-1]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	w2=${COMP_WORDS[COMP_CWORD-2]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	w3=${COMP_WORDS[COMP_CWORD-3]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
10
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    43
	  if [[ "$w1" == "--jack-client-name"             && "x$w0" == "x" ]];    then COMPREPLY=("'relpipe-in-jack'")
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    44
	elif [[ "$w1" == "--jack-connect-to-port"                          ]];    then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    45
	elif [[ "$w1" == "--required-jack-connections"    && "x$w0" == "x" ]];    then COMPREPLY=("0")
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	else
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		OPTIONS=(
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
			"--jack-client-name"
10
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    49
			"--jack-connect-to-port"
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    50
			"--required-jack-connections"
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		)
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	fi
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
complete -F _relpipe_in_jack_completion relpipe-in-jack