Convoluted Rake task setups simplified
Reiki (GitHub) — a bash function you can call with the command
r — is a shortcut for running rake tasks with arguments. No brackets, just spaces and commas (and colons to separate serial tasks).
This is currently working wonderfully for me, but I’m open to pull requests and the project will develop further if my needs expand.
I get a little crazy with my Rakefiles in cases where it’s my command central, such as my Jekyll blog or my app Marked 2 where I need to perform a wide variety of tasks with various arguments and sequences. Typing out task names with arguments in Rake’s command line syntax can be tedious with square brackets, commas, quoted arguments, etc. I build Reiki for my own sanity.
I get that most people don’t abuse Rakefiles to the extent that I do. You probably don’t need this if you’ve never made a TextExpander shortcut to fill in tedious task names.
Reiki is called with
r followed by the task or fragment of a task (fuzzy matched), followed by task arguments, commas separated, and optionally more tasks, separated by colons.
build task were the only task in your Rakefile starting with “b”:
=> rake build
Reiki uses fuzzy matching to figure out which task you want to run.
- If the first argument to
rfully matches a rake task and there are no other potential matches, it runs it with any following arguments as arguments for that task (e.g.
r build truebecomes
- If there is more than one possible match, it checks to see if the second argument makes sense as
$1_$2. If that’s the case, it runs that with additional arguments.
- If only the first letter(s) of a
$1_$2task are provided, it guesses and checks before running (e.g.
r f d jekyll bloggingbecomes
rake find_draft["jekyll blogging"]).
- Additional arguments are assumed to be a quoted string unless there are commas, in which case it combines them and automatically quotes only resulting arguments with spaces in them (e.g.
r gd true, publishing jekyll blogging postruns
rake gen_deploy[true,"publishing jekyll blogging post"]on my blog, and the
gen_deploytask takes an argument and a git commit message).
For example, in my Jekyll setup:
r fdr jekyll
=> rake find_draft[jekyll]
r fdf reiki bash
=> rake find_draft_fulltext["reiki bash"]
r gen true, commit message
=> rake generate[true,"commit message"]
You can separate multiple (serial) tasks with a colon (:). Arguments after a task and before a colon are treated as arguments to each task. Multiple tasks are run by rake as a series.
$ r bld xcode true: launch debug
=> rake build[xcode,true] launch[debug]
Reiki can automatically run the first match, or it can be set to verify with a question on the command line if there are multiple matches (or forced to always verify with the “quiet” option). A timeout can be set on the verification to automatically run if no response is provided.
If your Terminal supports color, output will be highlighted. If not, you’ll get clean output with no escape sequences.
reiki.plugin.bash to disk and source it in your
When loaded, it will define the
r command. Helpers are defined with
__r_ prefixes as a namespace.
If you use Bash-it, you can just drop it in your
You can configure defaults in the script (but see the next section to override them without modifying the original):
- to force a verification after guessing
- to change number of seconds to wait for verification, 0 to disable
- to force silent mode, using first option if multiple matches are found
- for verbose reporting
Defaults can be overriden by environment variables in your login profile/rc:
You can override the default configuration using switches as needed. Use
r -T to list options.
$ r -H
r: A shortcut for running rake tasks with fuzzy matching
Parameters are task fragments and arguments, multiple arguments comma-separated
$ r gen dep commit message
=> rake generate_deploy[commit message]
-h show options
-H show help
-T List available tasks
-v Interactively verify task matches before running
-a SECONDS Prompts run default result after SECONDS
-q Run quietly (use first match in case of multiples)
-d Output debug info
There’s an experimental completion function available for Bash in the reiki.completion.bash file. It mostly works for me, but has some issues and isn’t terribly necessary with something that takes shortcuts and fuzzy matches anyway…
Reiki is available for download on GitHub.
Speaking of reiki…