bash-completion.sh
branchv_0
changeset 11 07247893054e
parent 10 ded44e94147c
child 12 e8aae4d42c01
equal deleted inserted replaced
10:ded44e94147c 11:07247893054e
    11 # GNU General Public License for more details.
    11 # GNU General Public License for more details.
    12 #
    12 #
    13 # You should have received a copy of the GNU General Public License
    13 # You should have received a copy of the GNU General Public License
    14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
    14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
    15 
    15 
       
    16 _relpipe_in_jack_completion_read_nullbyte() { local IFS=; for v in "$@"; do export "$v"; read -r -d '' "$v"; done }
       
    17 
    16 _relpipe_in_jack_completion_ports() {
    18 _relpipe_in_jack_completion_ports() {
    17 	# TODO: simpler and faster implementation in relpipe-out-jack or relpipe-in-jack C++ code
    19 	if type relpipe-in-jack &> /dev/null && type relpipe-out-nullbyte &> /dev/null; then
    18 	jack_lsp -tp 2>/dev/null \
    20 		relpipe-in-jack --list-jack-ports true --list-midi-messages false 2>/dev/null \
    19 		| tr -d \\t \
    21 			| relpipe-out-nullbyte \
    20 		| tr \\n \\0 \
    22 			| while _relpipe_in_jack_completion_read_nullbyte "name" "input" "output" "physical" "terminal" "mine" "midi" "type"; do
    21 		| relpipe-in-cli \
    23 				 if [[ "$midi" = "true" && "$output" = "true" && "$mine" = "false" ]]; then echo "$name"; fi; done
    22 			--relation "jack_midi_port" \
    24 	fi
    23 			--attribute "name" string \
       
    24 			--attribute "properties" string \
       
    25 			--attribute "type" string \
       
    26 			--records-on-stdin true \
       
    27 		| relpipe-tr-grep '.*' 'properties' 'output' \
       
    28 		| relpipe-tr-grep '.*' 'type' 'midi' \
       
    29 		| relpipe-tr-cut '.*' 'name' \
       
    30 		| relpipe-out-nullbyte \
       
    31 		| tr \\0 \\n
       
    32 }
    25 }
    33 
    26 
    34 _relpipe_in_jack_completion() {
    27 _relpipe_in_jack_completion() {
    35 	local w0 w1 w2 w3
    28 	local w0 w1 w2 w3
    36 
    29 
    38 	w0=${COMP_WORDS[COMP_CWORD]}
    31 	w0=${COMP_WORDS[COMP_CWORD]}
    39 	w1=${COMP_WORDS[COMP_CWORD-1]}
    32 	w1=${COMP_WORDS[COMP_CWORD-1]}
    40 	w2=${COMP_WORDS[COMP_CWORD-2]}
    33 	w2=${COMP_WORDS[COMP_CWORD-2]}
    41 	w3=${COMP_WORDS[COMP_CWORD-3]}
    34 	w3=${COMP_WORDS[COMP_CWORD-3]}
    42 
    35 
       
    36 	BOOLEAN_VALUES=(
       
    37 		"true"
       
    38 		"false"
       
    39 	)
       
    40 
    43 	  if [[ "$w1" == "--jack-client-name"             && "x$w0" == "x" ]];    then COMPREPLY=("'relpipe-in-jack'")
    41 	  if [[ "$w1" == "--jack-client-name"             && "x$w0" == "x" ]];    then COMPREPLY=("'relpipe-in-jack'")
    44 	elif [[ "$w1" == "--jack-connect-to-port"                          ]];    then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
    42 	elif [[ "$w1" == "--jack-connect-to-port"                          ]];    then COMPREPLY=($(compgen -W "$(_relpipe_in_jack_completion_ports)" -- "$w0"))
    45 	elif [[ "$w1" == "--required-jack-connections"    && "x$w0" == "x" ]];    then COMPREPLY=("0")
    43 	elif [[ "$w1" == "--required-jack-connections"    && "x$w0" == "x" ]];    then COMPREPLY=("0")
       
    44 	elif [[ "$w1" == "--list-jack-ports"                               ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
       
    45 	elif [[ "$w1" == "--list-midi-messages"                            ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
    46 	else
    46 	else
    47 		OPTIONS=(
    47 		OPTIONS=(
    48 			"--jack-client-name"
    48 			"--jack-client-name"
    49 			"--jack-connect-to-port"
    49 			"--jack-connect-to-port"
    50 			"--required-jack-connections"
    50 			"--required-jack-connections"
       
    51 			"--list-jack-ports"
       
    52 			"--list-midi-messages"
    51 		)
    53 		)
    52 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    54 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    53 	fi
    55 	fi
    54 }
    56 }
    55 
    57