1 # -*- mode: shell-script; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
3 # Example bash aliases to improve your Drush experience with bash.
4 # Use `drush init` to copy this file to your home directory, rename and
5 # customize it to suit, and source it from your ~/.bashrc file.
7 # Creates aliases to common Drush commands that work in a global context:
10 # ddd - drush drupal-directory
12 # sa - drush site-alias
13 # sa - drush site-alias --local-only (show local site aliases)
14 # st - drush core-status
15 # use - drush site-set
17 # Aliases for Drush commands that work on the current drupal site:
19 # cr - drush cache-rebuild
20 # en - drush pm-enable
22 # unin - drush pm-uninstall
23 # updb - drush updatedb
26 # Provides several common shell commands to work better with Drush:
28 # ddd @dev - print the path to the root directory of @dev
29 # cdd @dev - change the current working directory to @dev
30 # lsd @dev - ls root folder of @dev
31 # lsd %files - ls "files" directory of current site
32 # lsd @dev:%devel - ls devel module directory in @dev
33 # @dev st - drush @dev core-status
34 # dssh @live - ssh to the remote server @live points at
35 # gitd @live pull - run `git pull` on the drupal root of @live
37 # Drush site alias expansion is also done for the cpd command:
39 # cpd -R @site1:%files @site2:%files
41 # Note that the 'cpd' alias only works for local sites. Use
42 # `drush rsync` or gitd` to move files between remote sites.
44 # Aliases are also possible for the following standard
45 # commands. Uncomment their definitions below as desired.
53 # These standard commands behave exactly the same as they always
54 # do, unless a Drush site specification such as @dev or @live:%files
55 # is used in one of the arguments.
57 # Aliases for common Drush commands that work in a global context.
59 alias ddd='drush drupal:directory'
60 alias ev='drush php:eval'
61 alias sa='drush site:alias'
62 alias st='drush core:status'
63 alias use='drush site:set'
65 # Aliases for Drush commands that work on the current drupal site
66 alias cr='drush cache:rebuild'
67 alias en='drush pm:enable'
68 alias pml='drush pm:list'
69 alias unin='drush pm:uninstall'
70 alias updb='drush updatedb'
71 alias q='drush sql:query'
73 # Overrides for standard shell commands. Uncomment to enable. Alias
74 # cd='cdd' if you want to be able to use cd @remote to ssh to a
83 # We extend the cd command to allow convenient
84 # shorthand notations, such as:
89 # You must use 'cddl' instead of 'cd' if you are not using
90 # the optional 'cd' alias from above.
91 # This is the "local-only" version of the function;
92 # see the cdd function, below, for an expanded implementation
93 # that will ssh to the remote server when a remote site
94 # specification is used.
100 # Use this function instead of 'cddl' if you have a very large number
101 # of alias files, and the 'cddl' function is getting too slow as a result.
102 # This function does not automatically set your prompt to the site that
103 # you 'cd' to, as 'cddl' does.
104 function fastcddl() {
109 elif [ "${s:0:1}" == "@" ] || [ "${s:0:1}" == "%" ]
111 d="$(drush drupal:directory $1 --local-only 2>/dev/null)"
117 t="$(drush site-alias $1 >/dev/null 2>/dev/null)"
120 echo "Cannot cd to remote site $s"
122 echo "Cannot cd to $s"
130 # Works just like the `cddl` shell alias above, with one additional
131 # feature: `cdd @remote-site` works like `ssh @remote-site`,
132 # whereas cd above will fail unless the site alias is local. If
133 # you prefer this behavior, you can add `alias cd='cdd'` to your .bashrc
139 elif [ "${s:0:1}" == "@" ] || [ "${s:0:1}" == "%" ]
141 d="$(drush drupal:directory $s 2>/dev/null)"
142 rh="$(drush sa ${s%%:*} --fields=host --format=list)"
150 c="cd \"$d\" \; bash"
151 drush -s ${s%%:*} ssh --tty
152 drush ${s%%:*} ssh --tty
162 # Allow `git @site gitcommand` as a shortcut for `cd @site; git gitcommand`.
163 # Also works on remote sites, though.
166 if [ -n "$s" ] && [ ${s:0:1} == "@" ] || [ ${s:0:1} == "%" ]
168 d="$(drush drupal-directory $s 2>/dev/null)"
169 rh="$(drush sa ${s%%:*} --fields=host --format=list)"
172 drush ${s%%:*} ssh "cd '$d' ; git ${@:2}"
174 echo cd "$d" \; git "${@:2}"
185 # Get a directory listing on @site or @site:%files, etc, for local or remote sites.
190 if [ ${a:0:1} == "@" ] || [ ${a:0:1} == "%" ]
192 p[${#p[@]}]="$(drush drupal:directory $a 2>/dev/null)"
193 if [ ${a:0:1} == "@" ]
195 rh="$(drush sa ${a%:*} --fields=host --format=list)"
208 drush $r ssh 'ls "${p[@]}"'
214 # Copy files from or to @site or @site:%files, etc; local sites only.
218 if [ ${a:0:1} == "@" ] || [ ${a:0:1} == "%" ]
220 p[${#p[@]}]="$(drush drupal:directory $a --local-only 2>/dev/null)"
229 # This alias allows `dssh @site` to work like `drush @site ssh`.
230 # Ssh commands, such as `dssh @site ls /tmp`, are also supported.
233 if [ ${d:0:1} == "@" ]
235 drush "$d" ssh "${@:2}"