a3120461658ad836fb87247999b20f1391e185e5
[yaffs-website] / vendor / drush / drush / examples / example.bashrc
1 # -*- mode: shell-script; mode: flyspell-prog; ispell-local-dictionary: "american" -*-
2 #
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.
6 #
7 # Creates aliases to common Drush commands that work in a global context:
8 #
9 #       dr               - drush
10 #       ddd              - drush drupal-directory
11 #       ev               - drush php-eval
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
16 #
17 # Aliases for Drush commands that work on the current drupal site:
18 #
19 #       cr               - drush cache-rebuild
20 #       en               - drush pm-enable
21 #       pml              - drush pm-list
22 #       unin             - drush pm-uninstall
23 #       updb             - drush updatedb
24 #       q                - drush sql-query
25 #
26 # Provides several common shell commands to work better with Drush:
27 #
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
36 #
37 # Drush site alias expansion is also done for the cpd command:
38 #
39 #       cpd -R @site1:%files @site2:%files
40 #
41 # Note that the 'cpd' alias only works for local sites.  Use
42 # `drush rsync` or gitd` to move files between remote sites.
43 #
44 # Aliases are also possible for the following standard
45 # commands. Uncomment their definitions below as desired.
46 #
47 #       cd                - cddl [*]
48 #       ls                - lsd
49 #       cp                - cpd
50 #       ssh               - dssh
51 #       git               - gitd
52 #
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.
56
57 # Aliases for common Drush commands that work in a global context.
58 alias dr='drush'
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'
64
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'
72
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
75 # remote site.
76
77 # alias cd='cddl'
78 # alias ls='lsd'
79 # alias cp='cpd'
80 # alias ssh='dssh'
81 # alias git='gitd'
82
83 # We extend the cd command to allow convenient
84 # shorthand notations, such as:
85 #   cd @site1
86 #   cd %modules
87 #   cd %devel
88 #   cd @site2:%files
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.
95 function cddl() {
96   fastcddl "$1"
97   use @self
98 }
99
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() {
105   s="$1"
106   if [ -z "$s" ]
107   then
108     builtin cd
109   elif [ "${s:0:1}" == "@" ] || [ "${s:0:1}" == "%" ]
110   then
111     d="$(drush drupal:directory $1 --local-only 2>/dev/null)"
112     if [ $? == 0 ]
113     then
114       echo "cd $d";
115       builtin cd "$d";
116     else
117       t="$(drush site-alias $1 >/dev/null 2>/dev/null)"
118       if [ $? == 0 ]
119       then
120         echo "Cannot cd to remote site $s"
121       else
122         echo "Cannot cd to $s"
123       fi
124     fi
125   else
126     builtin cd "$s";
127   fi
128 }
129
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
134 function cdd() {
135   s="$1"
136   if [ -z "$s" ]
137   then
138     builtin cd
139   elif [ "${s:0:1}" == "@" ] || [ "${s:0:1}" == "%" ]
140   then
141     d="$(drush drupal:directory $s 2>/dev/null)"
142     rh="$(drush sa ${s%%:*} --fields=host --format=list)"
143     if [ -z "$rh" ]
144     then
145       echo "cd $d"
146       builtin cd "$d"
147     else
148       if [ -n "$d" ]
149       then
150         c="cd \"$d\" \; bash"
151         drush -s ${s%%:*} ssh --tty
152         drush ${s%%:*} ssh --tty
153       else
154         drush ssh ${s%%:*}
155       fi
156     fi
157   else
158     builtin cd "$s"
159   fi
160 }
161
162 # Allow `git @site gitcommand` as a shortcut for `cd @site; git gitcommand`.
163 # Also works on remote sites, though.
164 function gitd() {
165   s="$1"
166   if [ -n "$s" ] && [ ${s:0:1} == "@" ] || [ ${s:0:1} == "%" ]
167   then
168     d="$(drush drupal-directory $s 2>/dev/null)"
169     rh="$(drush sa ${s%%:*} --fields=host --format=list)"
170     if [ -n "$rh" ]
171     then
172       drush ${s%%:*} ssh "cd '$d' ; git ${@:2}"
173     else
174       echo cd "$d" \; git "${@:2}"
175       (
176         cd "$d"
177         "git" "${@:2}"
178       )
179     fi
180   else
181     "git" "$@"
182   fi
183 }
184
185 # Get a directory listing on @site or @site:%files, etc, for local or remote sites.
186 function lsd() {
187   p=()
188   r=
189   for a in "$@" ; do
190     if [ ${a:0:1} == "@" ] || [ ${a:0:1} == "%" ]
191     then
192       p[${#p[@]}]="$(drush drupal:directory $a 2>/dev/null)"
193       if [ ${a:0:1} == "@" ]
194       then
195         rh="$(drush sa ${a%:*} --fields=host --format=list)"
196         if [ -n "$rh" ]
197         then
198           r=${a%:*}
199         fi
200       fi
201     elif [ -n "$a" ]
202     then
203       p[${#p[@]}]="$a"
204     fi
205   done
206   if [ -n "$r" ]
207   then
208     drush $r ssh 'ls "${p[@]}"'
209   else
210     "ls" "${p[@]}"
211   fi
212 }
213
214 # Copy files from or to @site or @site:%files, etc; local sites only.
215 function cpd() {
216   p=()
217   for a in "$@" ; do
218     if [ ${a:0:1} == "@" ] || [ ${a:0:1} == "%" ]
219     then
220       p[${#p[@]}]="$(drush drupal:directory $a --local-only 2>/dev/null)"
221     elif [ -n "$a" ]
222     then
223       p[${#p[@]}]="$a"
224     fi
225   done
226   "cp" "${p[@]}"
227 }
228
229 # This alias allows `dssh @site` to work like `drush @site ssh`.
230 # Ssh commands, such as `dssh @site ls /tmp`, are also supported.
231 function dssh() {
232   d="$1"
233   if [ ${d:0:1} == "@" ]
234   then
235     drush "$d" ssh "${@:2}"
236   else
237     "ssh" "$@"
238   fi
239 }