The script command could use a --script_path option that lets you define additional search paths for files.

I created a small patch that adds a --script_path option for the script command. You can define this option in drushrc.php.

// Specify additional directories to search for scripts
// Use POSIX path separator (':')
# $options['script_path'] = 'sites/all/scripts:profiles/myprofile/scripts';

I find this useful for building a customized library of drush scripts. Additionally, it removes the overhead of creating new commands for trivial pieces of functionality.

I have used this successfully on 5.x and 6.x sites.

Comments

moshe weitzman’s picture

Status: Needs review » Needs work

Sorry for my delay. Alas, does not apply cleanly anymore. Care to reroll?

Lets add an 'examples' item to the script command which illustrates how to use this.

srhaber’s picture

StatusFileSize
new2.01 KB

Apologies, that initial patch was created against 6.x-2.0.

Here's an updated patch created against the HEAD. It includes an 'examples' item.

moshe weitzman’s picture

Would be nifty if this command could list available scripts if no argument is provided. I guess we would mistakenly show some scripts in cwd() under soem use cases but i guess thats ok. Thoughts?

srhaber’s picture

I like that idea. We could group the results under their respective directories so the cwd() listing wouldn't cause too much clutter. I suspect we'd only care to display *.php files?

Even cooler would be to make this work with autocomplete magic #437568: Autocomplete awesomeness for drush.

moshe weitzman’s picture

yes, just .php extension

we should probably recurse down the specified search paths. but doing that on drush_cwd() would often give too many results so lets skip it there. drush has a directory walk function that seems appropriate for this.

moshe weitzman’s picture

One more idea. I have started using a scratch.php script where I just put a few lines of php that I want executed after a full bootstrap. It is a handy deb tool. I wonder if we should put a scratch.php in the distro and put it where it will be found by a script listing.

moshe weitzman’s picture

Status: Needs work » Fixed

Committed this patch with the improvements that I described.

Status: Fixed » Closed (fixed)

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

brad.bulger’s picture

StatusFileSize
new747 bytes

the script listing needs to use array_merge() instead of the '+' operator to add the scripts found in each directory in the path. '+' won't add new entries with keys matching existing keys, numeric keys included.

moshe weitzman’s picture

committed thanks.