I've been trying to remember to implement items from my zsh-dwim notes in my spare time. I managed to implement some apt and dpkg helpers this week.
You must use an HTML 5-compatible browser to view this video.
add-apt-repository -> apt-get update
Every six months I upgrade Ubuntu. I always end up having to add at least one or two PPA repositories, using the add-apt-repository command, every single time I upgrade. Just about every add-apt-repository command is followed by an apt-get upgrade. This transformation was definitely a no-brainer.
which -> dpkg -S -> apt-cache show
This one was a little less obvious, but probably just as useful. Often enough, I'm interested in finding out exactly which package the file returned by the which command belongs to. That usually means either typing dpkg -S and pasting in the path, or recalling the previous command from history and manually adding the dpkg -S and the required backticks.
That just seems like too much work. Now I just hit control-u, and the which command is converted directly into a correctly formatted dpkg -S command.
I ended up taking it one step further. Hitting control-u on a dpkg -S command will transform the command into a slightly buggy apt-cache show $(dpkg -S ) command. I'm not terribly happy with how the end result turned out; it ends up generating a rather verbose command.
Buy a good, comfortable, sturdy chair now rather than later
An Aeron would have been a pretty big expense for me fifteen years ago when I bought my first office chair. Just a few years later, though, and the price wouldn't have been too big of a big deal. I should have bought one a decade ago. I'd have been sitting more comfortably the entire time, and in the long run it would have been less expensive than buying a new, cheap chair every few years.
Not everyone finds the Aeron to be a comfortable chair. Fortunately there are plenty of other goodchairsto choose from. I'd definitely recommend spending some time sitting in them before you buy one, though.
My Progression of Chairs
At some point when I was in school, probably shortly before starting high school, my parents bought me a wooden office chair like this one. I remember them saying they got it at a yard sale for five or ten bucks. I would guess that I started sitting in that chair sometime around 1990, and I continued to sit in that chair through most of high school. I don't remember it being uncomfortable, but very little is uncomfortable when you're still under 140 pounds.
At some point that chair finally broke, and I upgraded to another wooden office chair, like this one. This one once belonged to my grandfather, and it is still at my parents' house today.
I replaced it with a random, cushioned, high back executive style chair at some point after I got out of high school, most likely sometime around 1997. Over the next decade or so I bet I bought a half dozen of these chairs, each for between $150 and $250. They weren't well made, and I often left them behind or gave them away when I moved.
The story of my Aeron Chairs
I finally convinced myself to buy an Aeron chair in the latter part of 2009. I ordered a used "Cobalt Classic," fully adjustable model through a vendor on eBay for around $450 shipped. The chair was in pretty good shape, and the label said it was manufactured in 1997. The sides where the arms meet the chair were pretty scuffed up, presumably from twelve years of adjusting, and it was a bit squeaky when leaning back.
About a year later, my father had a heart attack. I knew I'd be spending some time up there, so I drove the 900 miles up to my parents' house with the Aeron in the back seat. I was up there for about two months, and in that time we ended up ordering another Aeron for my father, and I left my "Cobalt Blue" Aeron behind for my mother.
Shortly before I left to return home I found another chair on eBay for myself. This one had the more common "Carbon Classic" color scheme, which is a black chair with a dark gray weave in the pellicle. This one was "new"; I believe it was some sort of floor model or something, fully adjustable, and has the newer levered locking mechanisms on the arms.
I have been visiting my parents again for the last six weeks or so, this time for back surgery. I am in my old bedroom, at my 20-year-old desk, sitting in that same "Cobalt Blue" Aeron chair. I'm not exactly sure why, but it no longer has a squeak when I lean back.
I still miss the blue chair a bit. It was a very nice-looking chair; the "Carbon Classic" is pretty boring in comparison. I'm pretty certain it is the same color as Sheldon Cooper's Aeron chair.
Why the Aeron chair? Aren't there better chairs now?
I'm certain there are better chairs available now. I can't say I've ever sat in any of them, though. The major selling point of the Aeron was the fact that I'd spent some time sitting in one in the past and I already knew I liked it. After that, the price and build quality of a used Aeron made a lot of sense.
My "Carbon Classic" Aeron chair has been in my possession now for almost four years. It looks and feels exactly the same as it did when I first got it. I expect to be able to say the same thing ten years from now.
Some people dislike the Aeron's pellicle seat. More specifically, they don't like the hard edge at the end of the seat. Some people say it cuts off the circulation in their legs. I'm a pretty heavy guy, and this has never been a problem for me. In fact, I don't think I'll ever buy an office chair with a cushion again.
The breathable pellicle seat is more comfortable on warmer days, and it even helps prevent swamp ass:
This little Perl program has been sitting in my ~/bin directory for almost a year now. It has quite a few features that I don't use very often, and some of those rarely used features seem to have a lot of bugs. Even so, I figured that it was time to throw it up on GitHub.
Fairly often, I get into a situation where I am performing different parts of the same task in two or more terminal windows. A lot of times I wish I had easier access to path and file names in the other window. I thought I'd write up a little script to automate the process.
I very quickly realized that it would be handy to be able to work with more than one file at a time, so emulating pushd and popd made a lot of sense. Since I was already planning to store the stacks in a file, I decided that they might as well be persistent.
What can you do with shtack?
I store the DNS names of some important servers in a stack called servers. I can use shstack's built-in for command to ping them all to see if they are alive.
Why reinvent the for loop?
I have two reasons. The first is shstack's "safe" for loop (sfor). The sfor loop works like a regular for loop, but it removes each item from the stack when the command is completed successfully. You might use this if you wanted to rsync a directory to multiple servers. That way, if there are any errors, you can easily fix the problem and run the command against the problematic servers again. I didn't end up using this as often as I expected, though.
I also wanted to be able to write very simple commands that used items from multiple stacks. In this example, I'm using rsync to back up three directories to two different remote servers:
Real world example: one of my backup scripts
I use Duplicity to make a backup of important parts of my home directory once a day. I have a script that runs right after this to copy those new backups out to a couple of servers out on the Internet. The script pulls those server names from a stack called rsyncDestinations:
#! /bin/bash
SRC=/mnt/platter/Backups/duplicity
source ~/.keychain/zaphod-sh
s for "echo Syncing $SRC to %rsyncDestinations%;
nice rsync -va --partial --delete --progress $SRC %rsyncDestinations%
"
Shstack definitely has some bugs. Some of them are just cosmetic, while others are pretty serious. I was going to record a screen cast showing off how sfor works, but I immediately noticed that sfor doesn't correctly handle file names with spaces. I was pretty surprised by this because I'm usually pretty good about making sure my code is space friendly.
Obviously, I'd like to fix some of these bugs. I'm sure I'll find others along the way too. I'd also like to write some documentation. I don't think the help screen is verbose enough to actually explain how to work it.
Not long after I got zsh-dwim up and running, I went mining in my old Zsh and Bash history files looking for potential transformation candidates. I thought I already implemented them all, but I was doing some spring cleaning and came across some of my notes. It turns out that I was wrong. There were still quite a few ideas in there that I haven't implemented yet.
One of the more interesting ideas in there was related to the find command. Each time I write anything more complicated than the simplest find command line, I usually follow the same careful workflow:
Run the command with no -exec option to make sure the correct files are chosen
Add the -exec option, but echo the commands first
Remove the echo, and run it one last time
As you can see in the video, that's precisely what this transformation does. If it isn't already there, hitting control-u will add the -exec echo {} \; to the command and put the cursor in front of the curly bracket. If the -exec is already followed by an echo, then the echo is removed.
For good measure, one more press of control-u will convert the -exec to a -print0 | xargs -0.
I wanted to be able to automatically place the cursor directly before the curly bracket, but I didn't have an existing mechanism to do that. The function that places the cursor after a successful transformation now sets the cursor position to the value of the _dwim_cursor variable, if it is defined.
I'm a bit bored. I'm sitting here watching my laptop download packages for my slightly early upgrade to Ubuntu 13.04. I figured this was as good a time as any to write about why I run Ubuntu.
I started my Linux journey sometime around 1996 with Slackware 3.0 on my old 40 MHz AMD 386 computer. A few years later, I tried SuSE for a little while. By the end of the decade I had finally found Debian, and I ran it on all my desktops, laptops, and servers.
The servers all ran Debian stable, the desktops and laptops usually ran Testing. As excellent as Debian is, there were problems in both of these cases.
Debian's release cycle was glacial at the time. Running Debian stable on a server was quite convenient as long as the release was only a year or two old, but it became harder and harder to install more modern software on those servers after that. At that point, you had to either manually upgrade some libraries, or you had to run the testing or unstable branch on your server.
On the desktop, Debian's stable release was almost always too outdated to use. The unstable branch was regularly broken, and the testing branch didn't always work either. Sometimes you'd run an apt-get upgrade and be stuck with a partially unusable system.
Ubuntu showed up in 2004 and gave me a solution to all of these problems. They were taking regular snapshots of Debian's unstable branch, polishing it up, and releasing it every six months. For me, this solved both of Debian's problems. I didn't have to wait three or more years for new stable releases, and I didn't have to take my chances running a branch that could be broken at any time.
Folks often look surprised when I tell them that I run Ubuntu. When they ask my why I run Ubuntu, I have always said that for my purposes, Ubuntu is Debian with a six-month release schedule. I don't use Unity, and I don't really use a full desktop environment, either. I use most of XFCE, but I replace the window manager with Sawfish.
My canned response has been getting less accurate over time. Ubuntu has been drifting farther and farther away from Debian with every release. Most people complain about the changes Canonical has been making to the default desktop environment, but I couldn't care any less about those changes than I already do.
It is the deeper, system-level changes that worry me more, but they haven't done anything to actually scare me away. Upstart has come close, though.
I won't be surprised if I end up looking for a better alternative in a few years. I also won't be surprised if that alternative ends up being Debian.
The upgrade to 13.04 is finished
As far as I'm concerned, this was an excellent upgrade. After the required reboot, almost everything looks exactly the same as it did before--everything but my weather applet, which seems to have switched itself over to the metric system.