Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serg/mtr-bash-completion enhancement #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions serg/mtr-bash-completion.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
_mtr_complete_testnames ()
{
dir=$1
[ -d $dir/t ] && dir=$dir/t
testnames=$( cd $dir && echo *.test | sed -e 's/\.test\>//g' )
dir="$1"
[ -d "$dir"/t ] && dir="$dir"/t
testnames=$( cd "$dir" && echo *.test | sed -e 's/\.test\>//g' )
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you actually test it with a path that contains spaces? Or you've quoted paths just in case, without testing?

_mtr_all_suites ()
{
suites=$(find suite ../{storage,plugin}/*/mysql-test -type d -exec find '{}' -maxdepth 1 -name '*.test' -print -quit \; | sed -E 's@/(t/)?[^/]+$@@; s@^(suite|.*/mysql-test)/@@'|sort -u)
suites=$(find "$sourcetestdir"/suite "$sourcetestdir"/../{storage,plugin}/*/mysql-test -type d -exec find '{}' -maxdepth 1 -name '*.test' -print -quit \; | sed -E "s@^$sourcetestdir/(suite|\.\./storage|\.\./plugin)/@@"'; s@/mysql-test@@; s@(/t)?/[^/]+\.test$@@'|sort -u)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sed line looks suspicious. I'd expect something like

sed -E "s@^$sourcetestdir/(suite|\.\./(storage|plugin)/mysql-test)/@@"'; s@(/t)?/[^/]+\.test$@@'

}
_mtr_complete()
{
[ -x ./mtr ] || return
[ -d main ] && main=main || main=.
sourcetestdir=$(sed -n -e "/^chdir/s/[^']*'\(.*\)');$/\1/p" < "$1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that works only for out-of-source mtr, right? what about "normal" in-source mysql-test-run.pl ?

cur=$2
prev=$3
case $prev:$cur in
*:--*)
opts=$( ./mtr --list )
opts=$( "$1" --list )
COMPREPLY=( $( compgen -W "$opts" -- $cur) )
;;
*:main.*)
_mtr_complete_testnames $main
[ -d "${sourcetestdir}/main" ] && dir="${sourcetestdir}/main" || dir="${sourcetestdir}"
_mtr_complete_testnames "$dir"
COMPREPLY=( $( compgen -P ${cur%.*}. -W "$testnames" -- ${cur#*.}) )
;;
*:?*.*)
for dir in {../{storage,plugin}/*/mysql-test,suite}/${cur%.*}; do
for dir in "${sourcetestdir}"/{suite,../{storage,plugin}/*/mysql-test}/${cur%.*}; do
if [ -d $dir ]; then
_mtr_complete_testnames $dir
break
Expand Down