Skip to content

Instantly share code, notes, and snippets.

@henriquemoody
Last active May 10, 2023 02:52
Show Gist options
  • Save henriquemoody/5014805 to your computer and use it in GitHub Desktop.
Save henriquemoody/5014805 to your computer and use it in GitHub Desktop.
PHPUnit Bash Completion. sudo curl -L https://gist.githubusercontent.com/henriquemoody/5014805/raw/phpunit.bash -o /etc/bash_completion.d/phpunit && source /etc/bash_completion.d/phpunit
# Bash-Completion script for PHPUnit
#
# Created by Henrique Moody <[email protected]>
#
_phpunit()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts="--coverage-clover --coverage-crap4j --coverage-html --coverage-php --coverage-text --coverage-xml --log-junit --log-tap --log-json --testdox-html --testdox-text --filter --testsuite --group --exclude-group --list-groups --test-suffix --report-useless-tests --strict-coverage --disallow-test-output --enforce-time-limit --disallow-todo-tests --process-isolation --no-globals-backup --static-backup --colors --columns --columns --stderr --stop-on-error --stop-on-failure --stop-on-risky --stop-on-skipped --stop-on-incomplete -v --verbose --debug --loader --repeat --tap --testdox --printer --bootstrap -c --configuration --no-configuration --include-path -d -h --help --version"
local diropts="--coverage-html|--coverage-xml|--include-path"
local nocompleteopts="--filter|--testsuite|--group|--exclude-group|--test-suffix|--loader|--repeat|--printer|-d|-h|--help|--version"
if [[ ${prev} =~ ${diropts} ]]; then
COMPREPLY=( $(compgen -d -- ${cur}) )
return 0
elif [[ ${prev} =~ ${nocompleteopts} ]]; then
return 0
elif [[ ${prev} = --columns ]]; then
COMPREPLY=( $(compgen -W "max" -- ${cur}) )
return 0
elif [[ ${prev} = --colors ]]; then
COMPREPLY=( $(compgen -W "auto never always" -- ${cur}) )
return 0
elif [[ "${cur}" == -* ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
else
COMPREPLY=( $(compgen -f -- "${cur}") )
return 0
fi
}
complete -F _phpunit phpunit
@drgomesp
Copy link

Great!

@henriquemoody
Copy link
Author

Thanks, @drgomesp.
I just tested on Fedora 17, I guess it works on other systems.

@hussani
Copy link

hussani commented Feb 22, 2013

I test on Ubuntu 12.04 and fully work.
Great job man!

@henriquemoody
Copy link
Author

Thanks, @hussani =)

@aik099
Copy link

aik099 commented May 15, 2014

Link in description leads to error page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment