Skip to content

Commit

Permalink
Small cleanup for shell aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Mar 27, 2011
1 parent 6025a75 commit 6cc8dd7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 64 deletions.
110 changes: 55 additions & 55 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ queries and DB migrations, and misc utilities like run cron or clear cache.

REQUIREMENTS
============
* To use Drush from the command line, you'll need a
* To use Drush from the command line, you'll need a
CLI-mode capable PHP binary version 5.2 or greater.

* Drush commands that work with git require git 1.7 or greater.

* Drush is designed a Unix-like OS (Linux, OS X)

* Some Drush commands run on Windows.
If you must run Drush on Windows, you have to install Unix Tools from
GnuWin32 (http://gnuwin32.sourceforge.net/). More info
about Drush on Windows available at http://drupal.org/node/594744.

* Drush works with Drupal 5, Drupal 6 and Drupal 7. However, occasionally
recent changes to the most recent version of Drupal can introduce issues
with Drush. On Drupal 5, Drush requires update_status v5.x-2.5 or later
Expand All @@ -37,45 +37,45 @@ INSTALLATION

STANDARD CONFIGURATION:
-----------------------
1. Place the uncompressed drush.tar.gz, drush.zip, or cloned git repository
1. Place the uncompressed drush.tar.gz, drush.zip, or cloned git repository
in a directory that is outside of your web root.

2. Make the 'drush' command executable:

$ chmod u+x /path/to/drush/drush

3. Configure your system to recognize where Drush resides. There are 2 options:

a) create a symbolic link to the Drush executable in a directory that is already in your PATH, e.g.:

$ ln -s /path/to/drush/drush /usr/bin/drush
b) explicitly add the Drush executable to the PATH variable which is defined

b) explicitly add the Drush executable to the PATH variable which is defined
in the the shell configuration file called .profile, .bash_profile, .bash_aliases, or .bashrc
that is located in your home folder, i.e.

export PATH="$PATH:/path/to/drush:/usr/local/bin"
(your system will search path options from left to right until it finds a result)

To apply your changes to your current session, either log out and then log back in again,
or re-load your bash configuration file, i.e.:

$ source .bashrc
NOTE: If you do not follow step 3, you will need to inconveniently run Drush commands using
the full path to the executable "/path/to/drush/drush" or by navigating to /path/to/drush

NOTE: If you do not follow step 3, you will need to inconveniently run Drush commands using
the full path to the executable "/path/to/drush/drush" or by navigating to /path/to/drush
and running "./drush". The -r or -l options will be required (see USAGE, below).

4. Test that Drush is found by your system:

$ which drush


AMP STACK CONFIGURATIONS:
-------------------------
Users of Apache distributions such as MAMP, XAMPP, or Acquia's Dev Desktop
will want to ensure that its php can be found by the command line by adding
it to the PATH variable, using the method in 3.b above. Depending on the
will want to ensure that its php can be found by the command line by adding
it to the PATH variable, using the method in 3.b above. Depending on the
version and distribution of your AMP stack, php might reside at:

/Applications/MAMP/bin/php5/bin MAMP (<=v.1.84)
Expand All @@ -85,7 +85,7 @@ version and distribution of your AMP stack, php might reside at:
/Applications/xampp/xamppfiles/bin XAMP (Mac)
/opt/lampp/bin XAMPP (Windows)

Most AMP stacks store mysql binaries in the same directory as php, so the
Most AMP stacks store mysql binaries in the same directory as php, so the
above paths cover both cases. MAMP is an exception in that it stores mysql elsewhere.
Adding mysql to your PATH is advisable, or Drush sql commands may fail:

Expand All @@ -108,24 +108,24 @@ Running a specific php-cli version for Drush
export DRUSH_PHP='/path/to/php'


Controlling how Drush is called via an shell alias
Controlling how Drush is called via an bash alias
- - - - - - - - - - - - - - - - - - - - - - - - - -
If you want to exactly control how Drush is called, you may define an alias
in your shell configuration file that executes the drush.php file directly and
in your shell configuration file that executes the drush.php file directly and
passes that path to Drush. Note that we can pass options to php if we want to,
but must also pass them to Drush with the '--php' option. We must also export
but must also pass them to Drush with the '--php' option. We must also export
the columns variable so drush output is properly formatted

alias drush='/path/to/php -d memory_limit=128M /path/to/drush/drush.php --php="/path/to/php -d memory_limit=128M"'
export COLUMNS


CONFIGURING PHP.INI
-------------------
Usually, php is configured to use separate php.ini files for the web server
and the command line. Make sure that Drush's php.ini is given as much memory
to work with as the web server is; otherwise, Drupal might run out of memory
when Drush bootstraps it.
and the command line. Make sure that Drush's php.ini is given as much memory
to work with as the web server is; otherwise, Drupal might run out of memory
when Drush bootstraps it.
To see which php.ini file Drush is using, run:

$ drush status
Expand All @@ -140,7 +140,7 @@ this file and change the settings described above without affecting the
php enviornment of your web server.

Alternately, if you only want to override a few values, copy example.drush.ini
from the "examples" folder into $HOME/.drush or the folder /etc/drush and edit
from the "examples" folder into $HOME/.drush or the folder /etc/drush and edit
to suit. See comments in example.drush.ini for more details.

Drush requires a fairly unrestricted php environment to run in. In particular,
Expand All @@ -150,37 +150,37 @@ disable_classes are empty.

INSTALLING DRUSH ON WINDOWS:
----------------------------
Windows support is lacking! Consider using on Linux/Unix/OSX
Windows support is lacking! Consider using on Linux/Unix/OSX
using Virtualbox or other virtual machine.
Drush 3 has proven more reliable than 4 for many users.

1. Drush depends on the following external packages:
Gzip, LibArchive, Tar, Wget, Less
Gzip, LibArchive, Tar, Wget, Less
which can be downloaded from
http://gnuwin32.sourceforge.net/packages.html
if you use cygwin, install the ncurses package to for tput support
http://invisible-island.net/ncurses/

2. bsdtar.exe is more reliable than tar.exe, so copy bsdtar.exe to tar.exe
C:\Program Files\GnuWin32\bin\bsdtar.exe
C:\Program Files\GnuWin32\bin\tar.exe

3. Set your PATH environment variable to include drush, php, and binaries installed above, i.e.
;C:\Program Files (x86)\php;C:\path\to\drush;C:\Program Files (x86)\GnuWin32\bin
(You will need to reopen your shell/command prompt window so the path variables refresh.)

4. To disable the warning about Windows support, set $options['check_os'] = FALSE
in drushrc.php. See examples/example.drushrc.php.

Whenever the documentation or the help text refers to
'drush [option] <command>' or something similar, 'drush' may need to be replaced by 'drush.bat'.

Complete Drush Windows installation documentation can be found at http://drupal.org/node/594744


USAGE
=====
Once you have completed the installation steps, Drush can be run in your shell
Once you have completed the installation steps, Drush can be run in your shell
by typing "drush" from within any Drupal root directory.

$ drush [options] <command> [argument1] [argument2]
Expand All @@ -192,7 +192,7 @@ Use the 'help' command to get a list of available options and commands:
For even more documentation, use the 'topic' command:

$ drush topic

For a full list of Drush commands and documentation by version, visit http://drush.ws

Many commands support a --pipe option which returns machine readable output.
Expand All @@ -201,9 +201,9 @@ For example, return a list of enabled modules:
$ drush pm-list --type=module --status=enabled --pipe

For multisite installations, use the -l option to target a particular site.
If you are outside the Drupal web root, you might need to use the -r, -l or
other command line options just for Drush to work. If you do not specify a URI
with -l and Drush falls back to the default site configuration, Drupal's
If you are outside the Drupal web root, you might need to use the -r, -l or
other command line options just for Drush to work. If you do not specify a URI
with -l and Drush falls back to the default site configuration, Drupal's
$GLOBAL['base_url'] will be set to http://default.
This may cause some functionality to not work as expected.

Expand All @@ -216,12 +216,12 @@ Related Options:
-v, --verbose Display verbose output.
--php The absolute path to your php binary.

The 'core-cli' command provides a customized bash shell, and the --pipe option
The 'core-cli' command provides a customized bash shell, and the --pipe option
lists the .bashrc code it uses, which you can import into your usual shell.

$ drush core-cli
Very intensive scripts can exhaust your available PHP memory. One remedy is to

Very intensive scripts can exhaust your available PHP memory. One remedy is to
just restart automatically using bash. For example:

while true; do drush search-index; sleep 5; done
Expand All @@ -232,17 +232,17 @@ DRUSH CONFIGURATION FILES
Inside /path/to/drush/examples you will find some example files to help you
get started with your Drush configuration file (example.drushrc.php),
site alias definitions (example.aliases.drushrc.php) and Drush commands
(sandwich.drush.inc). You will also see an example 'policy' file which
(sandwich.drush.inc). You will also see an example 'policy' file which
can be customized to block certain commands or arguments as required by
your organization's needs.

DRUSHRC.PHP
-----------
If you get tired of typing options all the time, you can add them as a shell alias,
but preferably can contain them in a drushrc.php file. Multiple Drush configuration
files can provide the flexibility of providing specific options in different site
directories of a multi-site installation.
See example.drushrc.php for examples and installation details.
If you get tired of typing options all the time you can contain them in a
drushrc.php file. Multiple Drush configuration files can provide the
flexibility of providing specific options in different site directories of a
multi-site installation. See example.drushrc.php for examples and installation
details.


SITE ALIASES
Expand All @@ -252,7 +252,7 @@ Once defined, aliases can be references with the @ nomenclature, i.e.

# Syncronize staging files to production
$ drush rsync @staging:%files/ @live:%files

# Syncronize database from production to dev, excluding the cache table
$ drush sql-sync --structure-tables-key=custom --no-cache @live @dev

Expand All @@ -261,7 +261,7 @@ See http://drupal.org/node/670460 and example.aliases.drushrc.php for more infor

COMMANDS
--------
Drush can be extended to run your own commands. Writing a Drush command is no harder
Drush can be extended to run your own commands. Writing a Drush command is no harder
than writing simple Drupal modules, since they both follow the same structure.

See sandwich.drush.inc for light details on the internals of a Drush command file.
Expand All @@ -270,13 +270,13 @@ Otherwise, the core commands in Drush are good models for your own commands.
You can put your Drush command file in a number of places:

a) In a folder specified with the --include option (see above).

b) Along with one of your existing modules. If your command is related to an
existing module, this is the preferred approach.

c) In a .drush folder in your HOME folder. Note, that you have to create the
.drush folder yourself.

d) In the system-wide Drush commands folder, e.g. /usr/share/drush/commands

In any case, it is important that you end the filename with ".drush.inc", so
Expand Down
6 changes: 1 addition & 5 deletions drush.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ function drush_main() {
foreach ($phases as $phase) {
if (drush_bootstrap_to_phase($phase)) {
// If applicable swaps in shell alias value (or executes it).
$return = drush_shell_alias_replace();
if (isset($return)) {
$command_found = TRUE;
break;
}
drush_shell_alias_replace();

$command = drush_parse_command();

Expand Down
4 changes: 2 additions & 2 deletions examples/example.drushrc.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
// Drush shell aliases act similar to git aliases.
// See https://git.wiki.kernel.org/index.php/Aliases#Advanced.
# $options['shell-aliases'] = array(
# 'pull' => '!git pull && drush updatedb',
# 'pulldb' => '!git pull && drush updatedb',
# 'noncore' => 'pm-list --no-core',
# 'wipe' => 'cache-clear all --verbose',
# 'wipe' => 'cache-clear all',
# );

// Load a drushrc.php configuration file from the current working directory.
Expand Down
4 changes: 2 additions & 2 deletions includes/command.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1235,8 +1235,8 @@ function drush_enforce_requirement_core(&$command) {
}

/*
* Check if a shell alias exists for current request. If so, pretend like the
* alias value was requested, along with any additional arguments.
* Check if a shell alias exists for current request. If so, re-route to
* core-execute like the and pass alias value along with rest of CLI arguments.
*/
function drush_shell_alias_replace() {
$args = drush_get_arguments();
Expand Down

0 comments on commit 6cc8dd7

Please sign in to comment.