Supporting continuity and open collaboration

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 ()
  [ -d $dir/t ] && dir=$dir/t
  testnames=`cd $dir && echo *.test | sed -e 's/.test>//g'`
  [ -x ./mtr ] || return
  case $cur in
      opts=`./mtr --list`
      COMPREPLY=( $( compgen -W "$opts" -- $cur) )
      _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) )
complete -F _mtr_complete mtr
complete -F _mtr_complete mysql-test-run
complete -F _mtr_complete


  1. 2011-10-29    

    Why not put it in /etc/bash_completion.d ?

    Will this be added to MariaDB/MySQL?

  2. Sergei Sergei

    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.

  3. Alexey Kopytov Alexey Kopytov

    Thanks for sharing this!

    /etc/bash_completion.d is only read if you have 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.