use relpipe-in-jack --list-jack-ports for bash-completion v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 07 Oct 2020 01:46:03 +0200
branchv_0
changeset 22 eebc16b7c3e4
parent 21 70b252d02a92
child 23 d2ad84dcf249
use relpipe-in-jack --list-jack-ports for bash-completion
bash-completion.sh
--- a/bash-completion.sh	Tue Oct 06 16:24:57 2020 +0200
+++ b/bash-completion.sh	Wed Oct 07 01:46:03 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_out_jack_completion_read_nullbyte() { local IFS=; for v in "$@"; do export "$v"; read -r -d '' "$v"; done }
+
 _relpipe_out_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' 'input' \
-		| 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_out_jack_completion_read_nullbyte "name" "input" "output" "physical" "terminal" "mine" "midi" "type"; do
+				 if [[ "$midi" = "true" && "$input" = "true" && "$mine" = "false" ]]; then echo "$name"; fi; done
+	fi
 }
 
 _relpipe_out_jack_completion() {