Skip to content

Instantly share code, notes, and snippets.

@carols10cents
Created April 17, 2014 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carols10cents/11015809 to your computer and use it in GitHub Desktop.
Save carols10cents/11015809 to your computer and use it in GitHub Desktop.
Test command with tab completion
# Add this to your .bashrc:
source ~/.test_completion.sh
# Create this file in your home directory and name it .test_completion.sh
_integration(){
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(ls test/integration)" -- $cur) )
}
complete -F _integration rti
_unit(){
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(ls test/unit)" -- $cur) )
}
complete -F _unit rtu

What is this?

I got tired of typing these all the time to run one test in our suite:

$ rake test TEST=test/unit/some_test.rb
$ rake test TEST=test/integration/some_integration_test.rb

Instead, I wanted to be able to do:

$ rtu s (tab complete to some_test.rb or other matching files in test/unit/)
$ rti s (tab complete to some_integration_test.rb or other matching files in test/integration/)

and have them run the same thing as the first set of commands. The following scripts let you do just that!

This guide was awesome in figuring out how to configure the filename completion: http://devmanual.gentoo.org/tasks-reference/completion/index.html

#! /bin/bash
# Create this file someplace in your PATH and make sure it's executable.
# I put this in ~/bin and added ~/bin to my PATH.
rake test TEST=test/integration/$1
#! /bin/bash
# Create this file someplace in your PATH and make sure it's executable.
# I put this in ~/bin and added ~/bin to my PATH.
rake test TEST=test/unit/$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment