Skip to content

Instantly share code, notes, and snippets.

@mathieuk
Created August 12, 2011 06:13
Show Gist options
  • Save mathieuk/1141556 to your computer and use it in GitHub Desktop.
Save mathieuk/1141556 to your computer and use it in GitHub Desktop.
Bash autocompletion function for the 'phpunit --filter' command.
shopt -s progcomp
_testnames()
{
local cur prev opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--filter"
if [[ $cur == -* || $prev == -* ]]; then
case "${prev}" in
"--filter")
local result=$(find ./ -name "*Test.php" | xargs egrep -hr -E 'function +test[A-Za-z0-9]*' -o | sed 's/function[ ]*//')
COMPREPLY=( $(compgen -W "${result}" -- ${cur}) )
return 0
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
else
COMPREPLY=( $(compgen -f -X "*Test.php" -- ${cur}) )
fi
return 0
}
complete -d -X '.[^./]*' -F _testnames phpunit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment