On the linux command line, using bash, we can easily create an executable php file and symlink to it from the /usr/bin path. Doing so will add coder_format as an executable command at the bash prompt.

In order to do this though, we need to change $_SERVER['PHP_SELF'], which points to the executed command, to the constant __FILE__. If this isn't done, we cannot include the coder_format.php file in our bash executable and have it work when symlinked.

Please refer to my attached patch, which doesn't break anything currently used in Windows or Linux, and the attached tarball containing the shell executable php code file.

If this is accepted, I'd be happy to also ammend the README.txt documentation to include suggested installation steps for coder-format.phps. For me I did this:

  1. Make the shell file executable
    $ chmod 755 scripts/coder_format/coder-format.phps
    
  2. Link to it from /usr/bin
    $ ln -sT /var/www/drupal6/sites/all/modules/coder/scripts/coder_format/coder-format.phps /usr/bin/coder-format
    

Comments

chop’s picture

Status: Active » Needs review

Anyone want to review my patch? Forgot to set appropriate status.

chop’s picture

StatusFileSize
new186 bytes
new828 bytes

Here's the patch. It didn't upload the first time.

chop’s picture

StatusFileSize
new1.13 KB

I've re-rolled my patch, with the added file now included (instead of in a separate tarball).

sun’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
Status: Needs review » Fixed
Issue tags: -script, -bash, -linux, -shell

Thanks! Instead of this, I've just committed a Drush coder-format command:
http://drupalcode.org/project/coder.git/commit/6547a06

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.