Reiki

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.

Why?

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.

Usage

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.

If a build task were the only task in your Rakefile starting with “b”:

r b
=> rake build

Reiki uses fuzzy matching to figure out which task you want to run.

  • If the first argument to r fully 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 true becomes rake build[true]).
  • 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_$2 task are provided, it guesses and checks before running (e.g. r f d jekyll blogging becomes 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 post runs rake gen_deploy[true,"publishing jekyll blogging post"] on my blog, and the gen_deploy task 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.

Installation

Bash

Add this to your ~/.bash_profile or ~/.bashrc:

source /path/to/reiki/r.bash

Tab completion is automatically enabled.

Zsh

Add this to your ~/.zshrc:

source /path/to/reiki/r.bash

Tab completion is automatically enabled.

Fish

Copy the Fish function to your Fish functions directory:

cp /path/to/reiki/fish/functions/r.fish ~/.config/fish/functions/r.fish

Or add to your ~/.config/fish/config.fish:

function r
    bash /path/to/reiki/r.bash $argv
end

Legacy Bash-it

The legacy reiki.plugin.bash file is also available for Bash-only setups. You can drop it in your ~/.bash_it/plugins/enabled folder if you use Bash-it.

Configuration

Config File

Reiki looks for a config file at ~/.rrc (or the path specified in $R_CONFIG). You can set defaults here:

# ~/.rrc
verify_task=1      # Force verification after guessing
auto_timeout=5     # Seconds to wait for verification (0 to disable)
quiet=1            # Silent mode, use first match if multiples found
debug=1            # Verbose reporting
bundle="bundle exec "  # Always use bundle exec

Environment Variables

You can override defaults using environment variables in your shell profile:

export R_CONFIG=~/my-custom-config    # Custom config file location
export R_VERIFY_TASK=true             # Force verification
export R_AUTO_TIMEOUT=5               # Verification timeout in seconds
export R_DEBUG=true                   # Debug mode
export R_QUIET=true                   # Quiet mode
export R_BUNDLE=true                  # Use "bundle exec" for all rake commands

Environment variables take precedence over config file settings.

Command Line Options

You can override configuration on a per-command basis:

Available options:

  • -h - Show options summary
  • -H - Show full help with examples
  • -v - Show version number
  • -V - Interactively verify task matches before running
  • -a SECONDS - Auto-run default match after SECONDS (overrides timeout)
  • -b - Run with “bundle exec” prefix
  • -q - Run quietly (use first match, no prompts)
  • -d - Output debug information
  • -T - List all available rake tasks

Examples:

r -V dep         # Verify before running deploy task if ther are multiple matches
r -b test unit   # Run with bundle exec: bundle exec rake test:unit
r -q build prod  # Quietly use first match for "build" with "prod" arg
r -d gen model   # Show debug output while matching "gen model"

Bash/Zsh Completion

Tab completion is automatically enabled when you source r.bash in Bash or Zsh! The completion function will:

  • Find your Rakefile (in current directory or git repository root)
  • Use the cached task list (.r_completions~)
  • Regenerate the cache automatically if needed
  • Provide intelligent task name completion

No additional setup or separate files needed. Just source r.bash and start using tab completion!

Note: The legacy reiki.completion.bash file is no longer needed with the improved r.bash.

Download

Reiki is available for download on GitHub.

Speaking of reiki…

Related Projects