A simple shell command for drupal cvs checkouts
#!/bin/bash
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-$2 -d $1 contributions/modules/$1There are lots of great Drupal productivity / development modules (e.g. drush, devel, coder) which due to their nature as modules need to be installed on each site you work on. If you work on a dizzying number of different Drupal sites, productivity improvements which are not site-specific are the most useful.
NB: this post is geared toward Mac users.
For Textmate I now have both the BoldSource bundle and the PHP Drupal bundle, which are both new. I also make great use of the Wim Leers command to instantly look up Drupal API functions from Textmate.
For the shell I sometimes use Steven Wittens' diff shortcut, and I also followed Textmate's instructions so that I can open files and projects in Textmate with the mate command (it always saves time to avoid Finder, whether via Quicksilver or command line).
If you ever (perpetually?) find yourself having to debug contributed modules it is important that you always download your modules from cvs- otherwise you will not be able to submit a patch for your work and will soon find yourself fixing the same thing again for your next project. Getting your modules from cvs is actually faster than downloading them from your browser and unpacking them into the right folder, but the cvs command itself can slow you down. For a while I have been using an alias to simplify checking out Drupal modules via cvs but I finally got around to setting up a proper bash command. I am pretty new to the wild world of command line geekery, but this is how I added a new command:
From your home directory, edit your .bash_profile file
cd ~
mate .bash_profile (or use another editor: vi .bash_profile)
(If you don't already have a .bash_profile file it will be created)
Add the line
export PATH=/usr/local/bin:$PATH
where /usr/local/bin will be the directory where you will add new commands. You can use a different directory if you please.
Navigate to that path where you can add new commands.
cd /usr/local/bin
The commands are just text files where the name of the command is the filename. I call my drupal cvs module checkout command 'drcvs'.
mate drcvs
Add the following:
#!/bin/bash
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-$2 -d $1 contributions/modules/$1Save the file and open a new shell. (You have to open a new shell for the .bash_profile changes to register.) You can now use the new command.
I use drcvs views 5--1-6 to do a checkout of views into my current directory. (I look up the version I want on the project page first.)






How would you then update a
How would you then update a contrib module? is there another bash script for that?
Path to Command is Relative to Computer, Not Home Directory
Thanks Jody, this is really helpful.
Thought I'd share share a mistake I made in case a reader might be stuck. I'm working on a MacBook.
I created the directories to make the path:
usr/local/binand put the drcvs file there. I kept getting "command not found." I knew the command was fine because it worked when I typed in, from the Home directory:usr/local/bin/drcvs.The mystery....
The "real" path was:
Users/MyAccount/usr/local/bin.So I just added the full path in the .bash_profile. I wouldn't have needed to do that if I had put the drcvs file in usr/local/bin relative to the computer as opposed to being relative to the home directory in my user account.
Terminal and I are friends again.
Shai
content2zero
Right. The key is to do cd
Right. The key is to do cd /usr/local/bin - that first / takes you to your computer's root. ~ takes you to your home directory. (try cd / and cd ~ for clarity)
I'm trying this on Ubuntu
I'm trying this on Ubuntu but it isn't working.
.../sites/all/modules$ dpl-get-module pathauto 5--2cvs server: cannot find module `pathauto' - ignored
cvs server: cannot find module `5--2' - ignored
cvs [checkout aborted]: cannot expand modules
Any ideas?
Oh
I just noticed the problem, I was trying to use an alias.
I added this function/command to .bashrc in my home folder.
dpl_get_module () {cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -r DRUPAL-"$2" -d "$1" contributions/modules/"$1"
}
Don't forget to do
source .bashrcafter saving..bashrc function works well
Thanks, Rowan.
I used this .bashirc alternative approach on Ubuntu and it works great. The setup is dead-simple, too.
I added a function for checking out Drupal core:
# CVS checkout Drupal core. Supply desired local directory name and version as parameters.dcvs_co_drupal () {
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout -d "$1" -r DRUPAL-"$2" drupal
}
So
dcvs_co_drupal mydrupal 6-10will check out Drupal 6.10 into a local directory named mydrupal.Cool :)
Thanks Jody... Definitely makes life easier!
BTW, for anyone getting "permission denied" change the file permissions...
cd /usr/local/binsudo chmod 755 drcvs:)
Yes--
Forgot to mention that step!
Thanks
That is a handy script.
Much appreciated.
>air guitar<
Post new comment