May 21, 2013 at 8:55 PM by Dr. Drang
It’s so easy to see the inefficiencies in someone else’s workflows, but so hard to see them in your own. When you do finally root out some clumsiness in your setup—no matter how small—and replace it with a more streamlined system, it’s a cause for celebration. This is a small celebratory post.
I’ve kept my scripts in a
~/bin directory pretty much since I started using Linux in ’97. I’m not sure if I learned to do that from someone’s explicit advice or if I just copied the idea from someone. Either way, it’s a pretty common setup in the Unix world: you create this
~/bin directory as a personal analog of
/usr/local/bin; you modify your
$PATH environment variable in
.bashrc1 to include that directory; and then any executable script saved in that directory can be run from the command line without specifying the full path to it. The advantages of saving to
~/bin instead of one of the system wide
- You don’t need superuser powers to save or modify files in
~/binwon’t get overwritten when you do a system update.
When I moved to the Mac in 2005, I kept this same setup and it’s served me well. But there’s always been one catch. If you have two computers, your
~/bin directories won’t stay in sync unless you create some clever piece of automation to keep each directory up to date with changes in the other. I never did that. I tended to move new scripts written on one computer to the other through CD-ROMs, then USB thumb drives, and then, finally, Dropbox. I often forgot to move scripts and didn’t realize it until I needed one that only on the other computer.
If you look up at the title of this post, you know what comes next, but for some reason it took me a couple of years of using Dropbox to figure it out. While it’s conventional in the Linux/Unix world to have your
~/bin directory just below your home directory, there’s no requirement for it to be there. It can be in any subdirectory of
~. In particular, it can be in
~/Dropbox/bin, where it will automatically sync between however many machines you have attached to that account.
Even after I finally realized this was the way to go, I didn’t pull the trigger. I don’t know why. Maybe it was because I’d lived so many years with out-of-sync
~/bin directories; maybe it was because the tradition of
~/bin was so strong I was afraid to change. Whatever, today I finally copied the contents of
~/bin at work into
~/Dropbox/bin and then did the same at home (skipping over duplicates), so
~/Dropbox/bin has all of my scripts. A quick edit of my
.bashrc to change
on both machines and the transformation was complete. I now have directories for my scripts on both computers that are automatically synced. Hooray!
In case you’re wondering, I have not deleted either
~/bin directory. There is absolutely no reason in the world for the new system to fail, which is all the more reason to keep a backup for when it does.
Or whatever the equivalent is for
zshif you’re one of those weirdos. ↩