bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Thu, 08 Oct 2020 16:45:50 +0200
branchv_0
changeset 13 326935d1bfab
parent 12 e8aae4d42c01
child 14 cde9bb07ea0a
permissions -rw-r--r--
add option --list-connections for listing JACK connections the output can be later sent to the relpipe-out-jack to restore the connection graph
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
11
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    16
_relpipe_in_jack_completion_read_nullbyte() { local IFS=; for v in "$@"; do export "$v"; read -r -d '' "$v"; done }
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    17
10
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    18
_relpipe_in_jack_completion_ports() {
11
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    19
	if type relpipe-in-jack &> /dev/null && type relpipe-out-nullbyte &> /dev/null; then
12
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    20
		relpipe-in-jack --list-ports true --list-midi-messages false 2>/dev/null \
11
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    21
			| relpipe-out-nullbyte \
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    22
			| while _relpipe_in_jack_completion_read_nullbyte "name" "input" "output" "physical" "terminal" "mine" "midi" "type"; do
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    23
				 if [[ "$midi" = "true" && "$output" = "true" && "$mine" = "false" ]]; then echo "$name"; fi; done
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    24
	fi
10
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    25
}
ded44e94147c add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    26
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
_relpipe_in_jack_completion() {
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	local w0 w1 w2 w3
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
	COMPREPLY=()
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	w0=${COMP_WORDS[COMP_CWORD]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	w1=${COMP_WORDS[COMP_CWORD-1]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	w2=${COMP_WORDS[COMP_CWORD-2]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	w3=${COMP_WORDS[COMP_CWORD-3]}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
11
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    36
	BOOLEAN_VALUES=(
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    37
		"true"
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    38
		"false"
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    39
	)
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    40
12
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    41
	  if [[ "$w1" == "--client"                       && "x$w0" == "x" ]];    then COMPREPLY=("'relpipe-in-jack'")
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    42
	elif [[ "$w1" == "--port"                         && "x$w0" == "x" ]];    then COMPREPLY=("'midi-in'")
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    43
	elif [[ "$w1" == "--connect-to"                                    ]];    then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    44
	elif [[ "$w1" == "--required-connections"         && "x$w0" == "x" ]];    then COMPREPLY=("0")
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    45
	elif [[ "$w1" == "--list-ports"                                    ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
13
326935d1bfab add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    46
	elif [[ "$w1" == "--list-connections"                              ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
11
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    47
	elif [[ "$w1" == "--list-midi-messages"                            ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	else
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		OPTIONS=(
12
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    50
			"--client"
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    51
			"--port"
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    52
			"--connect-to"
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    53
			"--required-connections"
e8aae4d42c01 simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents: 11
diff changeset
    54
			"--list-ports"
13
326935d1bfab add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    55
			"--list-connections"
11
07247893054e add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    56
			"--list-midi-messages"
8
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		)
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	fi
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
}
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
8ef1980db907 configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
complete -F _relpipe_in_jack_completion relpipe-in-jack