unix
Feb 11, 2009
Taming My $SHELL
I've been using the command line in various ways for a long time. Back in the DOS days it was the only way. Then windows came along, but there was still the need for a little 'cmd' action every once in a while. It wasn't until I started working at Six Feet Up that I re-kindled my love affair with the command line. This time around it was with unix and primarily ZSH.
I started out at Six Feet Up doing customer support and systems administration. This required learning a new skill set, the command line. As I made the transition from sysadmin to web developer this skill set transferred over quite nicely. It took me a little while to realize that all the things I was doing on the command line could be turned into shortcuts. My first run in with aliases involved the 'ls' command. Normal 'ls' output leaves a lot to be desired (especially for a n00b).
$ cd
$ ls
Applications Desktop Documents foo.txt Library runme
Ok, so foo.txt must be a file, but what the hell are all those other things? This is easily solved with some extra options that denote the type of item and color code things.
$ ls -GF
Applications/ Desktop/ Documents/ foo.txt Library/ runme*
Now it's clear that foo.txt is a file, runme is an executable and everything else is a directory. But who wants to type that every time? Not me. So what do we do? The solution is to modify your shell's startup files. In my case I would just add an alias to my .zshrc
.
alias ls="ls -GF"
Now when I type 'ls', it automatically adds the options in for me. This is old hat for a lot of command line hackers out there. For n00bs like I once was, this was a gold mine. I just recently published all my configuration files on github for mass consumption. This is the culmination of years of tweaking and prodding.
Once you get used to the comforts of a well defined set of user conf files you can never go back. This became a problem for me when Six Feet Up's hosting business started to really take off. Suddenly instead of five machines, we had ten, then twenty and more on the way. The obvious problem here is keeping all your shell customizations in sync. Luckily we have subversion configured on most of the machines.
At some point I had the bright idea to put all my confs into subversion. This made it really easy to get set up on a new machine.
$ ssh some-machine
Welcome to Some Machine!
$ svn co https://svn.example.com/svn/claytron/dotfiles .dotfiles
$ ln -s .dotfiles/.zshrc .
Now I could have the same .zshrc
file on all the servers fairly easily. With this setup, if I modified the conf on one server, then I could get the updates on the others. This worked well for a while. Then I started adding all my other confs into the mix. Settings for vim, screen and readline got added in. Now I had to go to each machine, update the checkout and symlink any new confs into my home directory. The solution for this slowly evolved into a shell script.
The current version has advanced in many ways since the original and has taught me a lot about shell scripting. This has solved the symlinking issue for me.
The only other problem is keeping up to date. I would log into a machine and never even think about updating the .dotfiles
dir to get the latest settings until something was missing. Then another lightbulb went off. Why not update them automagically? This is when I decided to put some code in to run an svn up
on the .dotfiles
dir each time I logged in. Here is what the current code looks like. It works like a charm for me in our environment.
The confs that are up on github now reflect all these trials and tribulations. They also blend bash and zsh together for me. I figure at a minimum most machines will have bash installed. So I went through and put all the 'common' elements into common files and put all the zsh or bash specific stuff into the respective startup files. Github also allows for an easy way to download my files in a tarball if I don't have access to svn or git. Github has continually impressed me since I started using it.
Now I'm ready to take over the world on almost any machine I log into :)