Bash completion script for CakePHP’s console

Published on and tagged with bake  cakephp  console

Travis Cline (aka tclineks) posted in a comment to the article “Faster baking of controllers with the bake shell script” a link to a bash completion script he started to write for CakePHP’s console.

As I didn’t understood what his script did nor how to use it, Travis explained it in the following way:

It [the bash completion script] gives you bash completion (through hitting tab) for shells and for the bake it gives you bake actions and will autocomplete potential model/view/controller names.

Here’s an intro to bash_completion:

after I source this (`. bashcompletion`, `source bashcompletion`, or link it in the right location -> /etc/bash_completion.d/) I can type

`(path to console)/cake [tab][tab]`

and it lists the potential shells to use e.g. acl, api, bake (even app-specific shells)

`/cake b[tab]` -> completes 'bake'

`/cake bake m[tab]` -> completes 'model'

If I further do

`/cake bake model M[tab][tab]` it'll complete for models beginning with 'M'

It’s pretty crude atm — doesn’t handle -app params (you can invoke the console within the custom app dir for now).

If bake.php/shell is enhanced to support public, noninteractive listing this could be pretty sweet.

The bash completion provided by this script when using the CakePHP console is really handy. Thanks Travis!

4 comments baked

  • tclineks

    Thank you for the mention Daniel — I see this being pretty useful with some things ironed out.

    One little bit I think is missing from my explanation: The `source bashcompletion` assumes you’ve saved the script to a file called bashcompletion (which is arbitrary).

    Probably more appropriately is `source (path to where you saved the completion script)`

    If I get a chance I’ll get patches together for opening up some of the internal listing for the relevant parts and get this cleaned up.

  • FallenJehova

    Great stuff Travis!

    Yesterday I tested the cake console and it’s great! This will be a great add-on for all the *xers out there.


  • Matt Huggins

    I’d like to build a console script in Cake that sends emails (newsletters) to users via a cron job. In doing so, I’d like to create a newsletter view template. I see that there is a “View” shell task, but if I’m not mistaken, it looks like this is intended to be used for baking a new project, not for accessing views within a custom shell. So my question is, is there an easy way to access views from a shell console script?

  • Matt Huggins

    Durr, I posted this last comment under the wrong article here, feel free to delete it. I re-posted it under the correct article. Sorry!

© daniel hofstetter. Licensed under a Creative Commons License