bash-completion.sh
branchv_0
changeset 11 07247893054e
parent 10 ded44e94147c
child 12 e8aae4d42c01
--- a/bash-completion.sh	Tue Oct 06 16:55:22 2020 +0200
+++ b/bash-completion.sh	Wed Oct 07 01:45:30 2020 +0200
@@ -13,22 +13,15 @@
 # You should have received a copy of the GNU General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
+_relpipe_in_jack_completion_read_nullbyte() { local IFS=; for v in "$@"; do export "$v"; read -r -d '' "$v"; done }
+
 _relpipe_in_jack_completion_ports() {
-	# TODO: simpler and faster implementation in relpipe-out-jack or relpipe-in-jack C++ code
-	jack_lsp -tp 2>/dev/null \
-		| tr -d \\t \
-		| tr \\n \\0 \
-		| relpipe-in-cli \
-			--relation "jack_midi_port" \
-			--attribute "name" string \
-			--attribute "properties" string \
-			--attribute "type" string \
-			--records-on-stdin true \
-		| relpipe-tr-grep '.*' 'properties' 'output' \
-		| relpipe-tr-grep '.*' 'type' 'midi' \
-		| relpipe-tr-cut '.*' 'name' \
-		| relpipe-out-nullbyte \
-		| tr \\0 \\n
+	if type relpipe-in-jack &> /dev/null && type relpipe-out-nullbyte &> /dev/null; then
+		relpipe-in-jack --list-jack-ports true --list-midi-messages false 2>/dev/null \
+			| relpipe-out-nullbyte \
+			| while _relpipe_in_jack_completion_read_nullbyte "name" "input" "output" "physical" "terminal" "mine" "midi" "type"; do
+				 if [[ "$midi" = "true" && "$output" = "true" && "$mine" = "false" ]]; then echo "$name"; fi; done
+	fi
 }
 
 _relpipe_in_jack_completion() {
@@ -40,14 +33,23 @@
 	w2=${COMP_WORDS[COMP_CWORD-2]}
 	w3=${COMP_WORDS[COMP_CWORD-3]}
 
+	BOOLEAN_VALUES=(
+		"true"
+		"false"
+	)
+
 	  if [[ "$w1" == "--jack-client-name"             && "x$w0" == "x" ]];    then COMPREPLY=("'relpipe-in-jack'")
 	elif [[ "$w1" == "--jack-connect-to-port"                          ]];    then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
 	elif [[ "$w1" == "--required-jack-connections"    && "x$w0" == "x" ]];    then COMPREPLY=("0")
+	elif [[ "$w1" == "--list-jack-ports"                               ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
+	elif [[ "$w1" == "--list-midi-messages"                            ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
 	else
 		OPTIONS=(
 			"--jack-client-name"
 			"--jack-connect-to-port"
 			"--required-jack-connections"
+			"--list-jack-ports"
+			"--list-midi-messages"
 		)
 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
 	fi