bash completion for mysql-test-run
For many years I was using tcsh, with lots of useful customizations, that were created during these years. Now I have bash on my laptop and slowly adding what I’ve got used to.
Yesterday I’ve created command line completion rules for mysql-test-run. It’s not a complete set of everything that’s possible, still it’s quite useful as it is. I need to type much less now when invoking mysql-test-run (and I invoke it quite a lot).
If you’d like to try it, paste the below in your ~/.bashrc:
_mtr_complete_testnames () { dir=$1 [ -d $dir/t ] && dir=$dir/t testnames=`cd $dir && echo *.test | sed -e 's/.test>//g'` } _mtr_complete() { [ -x ./mtr ] || return cur=${COMP_WORDS[COMP_CWORD]} case $cur in --*) opts=`./mtr --list` COMPREPLY=( $( compgen -W "$opts" -- $cur) ) ;; main.*) _mtr_complete_testnames . COMPREPLY=( $( compgen -P ${cur%.*}. -W "$testnames" -- ${cur#*.}) ) ;; ?*.*) _mtr_complete_testnames suite/${cur%.*} COMPREPLY=( $( compgen -P ${cur%.*}. -W "$testnames" -- ${cur#*.}) ) ;; *) _mtr_complete_testnames . suites=`cd suite && echo main * | sed 's/>/./g'` COMPREPLY=( $( compgen -W "$testnames $suites" -- $cur) ) ;; esac } complete -F _mtr_complete mtr complete -F _mtr_complete mysql-test-run complete -F _mtr_complete mysql-test-run.pl
Why not put it in /etc/bash_completion.d ?
Will this be added to MariaDB/MySQL?
I’ve never thought of it, frankly speaking. But yes, you’re right. Why not? Thanks for the idea.
I could add it to the source tree, and then we can include it in mariadb .deb and .rpm packages.
Thanks for sharing this!
/etc/bash_completion.d is only read if you have http://bash-completion.alioth.debian.org/ installed, whereas the original recipe depends only on bash.
OTOH, if you have bash-completion installed (and you normally have), you can also add those lines to ~/.bash_completion which is less intrusive.