ninetydegrees (90d)☕ (
ninetydegrees) wrote in
dw_dev_training2013-06-16 11:16 pm
Entry tags:
Very basic scripts for newbies
I have two scripts I use all the time and which have saved me much grief and hair pulling. I was told there were worth sharing so here I am doing just that. :)
The first one just checks which branch you're on both in dw-free and nonfree (it's basically git branch with a bow):
See? There's nothing particularly smart about this but I run it every time I start working on something. This goes into ####-USERNAME/bin on your hack and is made executable with
The second one just checkouts develop for me on both branches and brings me back to /dw. See alierak's comment for an actual working way of doing this. :)
You can of course modify them to better fit your workflow or use Jeshyr's omnibus script instead. If you have interesting scripts, do share them in the comments please!
The first one just checks which branch you're on both in dw-free and nonfree (it's basically git branch with a bow):
#!/bin/bash
echo "..."
echo "dw-free"
echo "..."
cd $LJHOME
git branch
echo "..."
echo "dw-nonfree"
echo "..."
cd $LJHOME/ext/dw-nonfree
git branchSee? There's nothing particularly smart about this but I run it every time I start working on something. This goes into ####-USERNAME/bin on your hack and is made executable with
chmod ugo+x ~/bin/SCRIPTNAMEThe second one just checkouts develop for me on both branches and brings me back to /dw. See alierak's comment for an actual working way of doing this. :)
You can of course modify them to better fit your workflow or use Jeshyr's omnibus script instead. If you have interesting scripts, do share them in the comments please!

no subject
That said, while at YAPC I banged my head on git for a while when trying to patch EmailPost.pm and being completely unable to find it. Turns out my dwu script left me on the master branch, which is apparently a bad place to try to get anything done. I switched around the order of branch updates in my script so it leaves me on the develop branch.
no subject
Oh god. Something similar happened to me which is why I created these scripts in the first place. I also edited dwu to prevent this from happening again.
no subject
Suppose the second script is called "dev" and you've put it in your bin directory, made it executable with chmod, etc., so you can run it just by typing "dev". Now try this sequence of commands:
cd /tmppwd
dev
pwd
It should report that you're in /tmp both times. It doesn't leave you in $LJHOME because "dev" isn't actually running "cd" commands in your shell -- it's running them in a new, separate process that has its own idea of the current directory. The shebang line at the beginning of the script is what tells the OS what interpreter to run, not necessarily the same as your login shell, and the contents of the script are sent to the new process as standard input. It does whatever it does and then exits. If makes changes to the filesystem like creating files or switching git branches, obviously those will stick around. But anything it does with setting variables, changing its idea of the current directory, etc., that are essentially the local state of a shell? Those just go away when it exits.
So there are a couple of ways to make those sorts of changes happen in your login shell instead. One is to run the script by typing ". dev" or "source dev" instead of just "dev". Instead of starting a new process, using the shebang line, etc., this just tells your shell to read the file and treat it as input, as though you'd typed it in as a sequence of commands.
The other way to do this sort of thing is, instead of writing a script, you can write a shell function or alias so that typing "dev" runs a predefined sequence of commands in your shell, but doesn't involve reading them from a file called "dev". For example, if you add this function to your .bash_aliases:
dev() {cd $LJHOME
git checkout develop
cd $LJHOME/ext/dw-nonfree
git checkout develop
cd $LJHOME
}
Then either log out and log back in or "source .bash_aliases", and you should be able to just type "dev" and have it change branches *and* leave you in $LJHOME.
no subject
no subject
no subject