Whole Disk Encryption with an SSD

I’ve been wanting to encrypt the drives in my laptop for quite some time now. I was putting it off for a couple of reasons. I know that the processor in my laptop can’t decrypt fast enough to keep up with my Crucial M4’s 300+ MB per second read speeds. I also wasn’t too excited about the extra CPU overhead reducing my already limited amount of battery run time.

I finally decided to give it a try anyway. There are a few security-related issues to watch out for, and I have some specific problems that I have to work around with my particular laptop.

Much of this should apply to almost any SSD or operating system. I am currently running Ubuntu 12.10, and I am almost positive I am using the Ubuntu installer’s default encryption options. Whatever you are using, be certain to choose a good, long pass phrase.

Show:

Performance and battery life

I have effectively cut my maximum sequential read speeds in half. My Crucial M4 can read at 330 MB per second, and my old Intel X25-M was only about 30 MB per second slower than that. The Intel Core i7-720QM in my laptop does not have Intel’s new encryption acceleration instructions. It can only encrypt at about 140 MB per second.

Sequential read performance is the only benchmark statistic that breaks that 140 MB per second barrier. In day-to-day use, my laptop isn’t noticeably slower now than before I encrypted it.

Just about the only thing that might be noticeably slower would be copying large files around. Most of the time, when I do this a slower device is the bottleneck, like my second 7200 RPM drive, or a network drive. Even a copy from one location to another on the SSD is going to be bottlenecked quite a bit by the slower write speeds.

I haven’t done any properly scientific battery life tests. The battery life of my big, old desktop replacement style laptop was never good to begin with. I’m pretty confident that battery life under normal use hasn’t been significantly impacted, though. I just don’t do all that much disk I/O on the rare occasions that I am away from my desk.

Security and TRIM/discard

Solid-state drives have a feature that allows the operating system to alert the drive that a disk block is now empty. This lets the drive reclaim unused blocks. These reclaimed blocks can be erased while the drive is idle. A well TRIMmed SSD tends to perform better than an unTRIMmed one. Some drives are more reliant on TRIM than others, though.

This creates a small problem for encryption, though. Normally, an encrypted drive is one big solid block of seemingly random data. Once you start TRIMming that drive there will be “holes” full of zeroes almost anywhere that you have deleted a file.

Depending on how far you lean to the side of paranoia, this could definitely be a problem. I’m also under the impression that this might damage TrueCrypt’s “hidden volumes.”

I am not one with this level of paranoia. I also don’t have anything on this laptop worth protecting from the “lead pipe” password crackers.

If you want to enable TRIM support, you will need to make sure it is enabled in both your /etc/fstab file AND your /etc/crypttab file. I hadn’t thought to check the latter when I first set this up.

A snippet from my own /etc/crypttab file:

sda5_crypt UUID=f329fc5a-04ab-43cf-b762-0db126b31c26 none luks,discard

I am unhappy with the performance of on-the-fly TRIM on my Crucial M4. I just run fstrim manually every once in a while. I am pretty sure you will still need the discard pass through option enabled in your /etc/crypttab file in order for fstrim to function.

NVidia’s stupid drivers

This particular problem most likely only affects a very small number of users. NVidia’s proprietary driver does not yet allow me to activate any external screens during the boot process. My laptop spends most of its time hiding away in its little cradle connected to a pair of external monitors. This means that I can’t see the pass phrase prompt if I boot my laptop while it is “docked.”

The open source Nouveua drivers will do this just fine automatically. Unfortunately for me, they aren’t up to my requirements for gaming performance.

I imagine that on some random day in the future this won’t be a problem anymore. Then I will get to discover whether or not my Bluetooth keyboard is functional that early in the boot process. I expect that it isn’t, but that should be easy enough to fix.

It is a good thing I rarely turn this thing off…

Setting Up a Piwik Notification on Android with Tasker

Update: You might want to skip all of this. My friend Brian took what I had here quite a bit further, and he has made a much more comprehensive Piwik notification for Tasker. You should definitely check it out!

I’ve been using Piwik to monitor and analyze web traffic for quite a while now. The Piwik app for Android is pretty good, but I was hoping to be able to see a quick overview without opening and drilling down into the Piwik app.

Luckily for me, my old friend Tasker was more than capable of helping me out here. Tasker was one of the first two apps I bought for my HTC Dream, and I’ve been relying on it ever since. I mostly use Tasker for things like turning my phone’s Wi-Fi on when I get home and automatically turning off Bluetooth when my headset is disconnected. One of my friends uses it to automatically open his OBDII logger when he plugs his phone into his car.

This time I am using Tasker to periodically download data from Piwik and create an Android notification out of the important bits. Most of this was pretty simple. Piwik will export data in a number of different formats. Tasker seemed to be best suited to parsing a CSV file but the way I ended up doing it would most definitely be considered cheating.

I’m all right with that, though, because it works!

On the tablet On the phone

You will want to edit these lines before you import this profile:

<Str sr="arg0" ve="3">YourHostName.com</Str>
<Str sr="arg1" ve="3">/piwik/?module=API&amp;idSite=2&amp;date=today&amp;period=day&amp;method=VisitsSummary.get&amp;format=csv&amp;token_auth=YourAuthTokenGoesHere</Str>

You will want to supply the correct Piwik server name, site id (idSite=), and auth token (token_auth=…). These can be modified in Tasker after the profile has been imported, but it is probably less effort doing so with a real keyboard and text editor.

The Tasker site very briefly explains how to import a profile. You can download my Tasker Piwik profile here:

Piwik.prf.xml

A Small Update to `zsh-dwim`: rsync and dstat

I recently added transformations for two more commands, dstat and rsync, to zsh-dwim. These new transformations aren’t exactly in line with zsh-dwim’s original goal.

Almost all of zsh-dwim’s transformations up to this point have been about laziness. If you untar something, zsh-dwim will let you cd right into the directory it was extracted to without having to guess at the directory name. If you fail to ssh into a host, it will construct the command to remove that host from your known_hosts file for you.

These new transformations aren’t just about laziness. They are also about memory. They’re helping me spend less time referring to man pages and more time running commands.

The new, simple rsync transformations

I use rsync quite a bit. Most of the time I only care about moving some data around and I don’t care one bit about permissions, hard links, or crossing file system boundaries. Once every few months, though, I do care about these things, and when I do, they are VERY important.

I always know off the top of my head to run rsync -a for “archive,” but when you’re trying to effectively clone a drive, this isn’t really enough. You might very well need to copy ACLS and extended attributes. You will almost certainly want to handle sparse files correctly.

I don’t know about you, but on the rare occasions when I need these options, I end up checking and rechecking the rsync man page to make sure I didn’t miss anything. Having the whole set of options (-aHAXS in my case) pop up at the press of a button is handy. It’ll be even handier in a few months when I forget all this and need to do it again.

The new, simple dstat/vmstat transformations

I started using dstat some-time last year instead of vmstat. It has much nicer, colorized output and it can monitor quite a bit more things than vmstat. In fact, I have vmstat aliased to dstat (specifically dstat -cpgdms -D total).

The two things I tend to want to monitor with dstat are the usual vmstat numbers and disk I/O. I would often build up a dstat command to monitor a specific block device, but lately I have found that dstat -f is all I really need, so at this point zsh-dwim toggles between vmstat and dstat -f.

Why not just use aliases?

I had already given this a lot of though, even before reading comments about using aliases instead of zsh-dwim on Reddit. Aliases are wonderful and I use them all the time. I have two problems with them, though.

First of all, I have to remember that I have the alias that I need. For commands that I use daily or weekly this should be pretty easy. I don’t make “perfect” clones with rsync often enough to remember that I have an alias for that.

The other problem with aliases, and this is my biggest concern lately, is that they hide the command that you’re actually running. Most of the time, this opacity is welcomed. I really don’t care that when I run vmstat it is actually running a more complex dstat command, but I most definitely want to see which switches are being passed to rsync. It makes it easier to modify them or add more switches.

There are ways around some of this opacity but I’m only willing to do it with my global aliases. Automatically expanding much else would just be too noisy.

Future plans for zsh-dwim

I’m keeping my eye open for more commands that I tend to run in series so that I can turn them into transformations. I’m running pretty low on ideas, though. I’ve optimized my own workflow pretty nicely already. I’m more a sysadmin type, though. I’d really be interested in hearing from some programmer types. There have to be some git-related workflow ideas that I could add to zsh-dwim, but I’m just too light of a git user to know what they are.

If you have any ideas please, don’t hesitate to leave a comment or send me an email! Thoughts and opinions are probably worth more to the zsh-dwim project than code contributions at this point.

SSD Upgrade: Intel X25-M to Crucial M4

Back in June I decided that we should put an SSD in Chris’ laptop (a.k.a. my old laptop). I ended up buying a new solid state for myself and moving my Intel X25-M into her laptop.

Shopping for an SSD this time was a very different experience. When I bought my first SSD there was really only one drive worth buying; I just had to wait until I saw the best possible price on that drive. These days the majority of solid-state drives are fast and well made. I just had to find a reasonably priced drive of the size I want and Google a bit just to make sure that it isn’t a lemon.

Show:

Version 1.03c                             ------Sequential Output------- --Sequential Input-  --Random-
                                          -Per Chr- --Block-- -Rewrite-- -Per Chr- --Block--  --Seeks--
Machine                              Size K/sec %CP K/sec %CP  K/sec %CP K/sec %CP K/sec %CP  /sec %CP
Xen Server (4x400 RAID 10)             1G 68909  97 128789 45  48402  18 55770  91 106948  24   326   0
Intel X25-M 80 GB                      8G 56415  89  87157 11  39827   9 69707  98 298590  29 16150  45
Crucial M4 128 GB                     16G   954  98 183205 20 105877   9  4858  99 327088  16  4306 120
Crucial M4 128 GB aes-256, nodiscard  16G   604  94 152764 16  63475   6  4064  98 145506   6  2380  46
Crucial M4 128 GB aes-256, pre-trim   16G   794  97  56071  6  58384   7  3861  98 121742   8 10462 167
Crucial M4 128 GB aes-256, discard    16G   724  94  28447  2  22498   2  3948  96 134872   5  2361  45
Crucial M500 480 GB aes-256           63G   483  99 406072 55 150005  34  1362  99 309761  38 +++++ +++

The Crucial M4 128 GB

I ended up settling on the Crucial M4 128 GB solid state drive. It really isn’t much of an upgrade over the Intel X25-M. It is measurably faster, but I can’t notice the difference. The leap from a traditional hard drive with glacial seek times to a solid-state drive was very noticeable. The X25 is already so fast that the incremental upgrade isn’t easy to feel.

The extra 48 GB of space is very, very noticeable. My gargantuan laptop has room for two hard drives. I was using symlinks to move some larger directories out of my SSD and onto the extra disk, mostly things like my downloads directory, virtual machine images, and larger games like Team Fortress 2.

The Intel X25 usually ran about half full because of this. Today, with all that cruft moved back to the SSD, the Crucial M4 tends to hover right around 75% full.

What the benchmarks say

First I would like to note that something has changed somewhere between my documented X25-M benchmark and today. I don’t currently know why the “per character” speeds on these benchmarks are so low. I do know that I’ve gotten similar results this year from the X25-M, but I didn’t save any of those results.

The Intel X25-M and the Crucial M4 have very comparable read performance on my SATA 2 controller. When I benchmarked the X25-M a few years ago I thought for sure it was maxing out the SATA 2 port. The Crucial M4 proved me wrong, though. It is able to eke out an extra 10%.

The Crucial M4 definitely performs writes faster than the Intel X25-M. It is too bad Bonnie doesn’t measure the small random writes that most early solid-state drives were so terrible at.

Why do I use Bonnie for benchmarks?

I’ve been using Bonnie forever. I remember some scores from almost a decade ago and I bet I could even dig some up out of old backups. I remember watching the folks from 3Ware running Bonnie benchmarks at Linux Expo back in 2001. I’m mostly still running and comparing Bonnie benchmarks for historical reasons.

The Crucial M4’s horrendous TRIM speed

At some point in the last five months I’ve encrypted my entire laptop. This is only partially relevant here because it turns out that I forgot to enable TRIM “pass through” on my encryption layer. I noticed this when my first benchmark for this article came out way slower than I thought it would. I did run a benchmark right after I encrypted the drive, but I either misplaced it or didn’t save it.

The first thing I did when I noticed this was to enable TRIM/discard everywhere I could, manually run fstrim, reboot, and ran another benchmark. That is when I got the horrible, horrible 20 to 30 MB/sec write speeds. It was so awful that I couldn’t even use the laptop while the benchmark was running.

After disabling the discard option, the write speeds improved by 300% and 500%. A freshly trimmed drive with discard turned off runs about as fast as I would hope, right around the maximum speed my CPU can perform AES-256. My laptop was still responsive during the benchmark.

I will definitely be leaving discard turned off on this drive. I’ll just have to manually run fstrim every once in a while. TRIM on the X25-M did not incur this much of a performance penalty.

Was it worth the trouble and cost of upgrading from the Intel X25-M?

No. It was not. The X25-M is still an excellent drive. My real goal here was to remove the spinning drive from another computer. If I weren’t doing that, this wouldn’t have been worth the time, effort, or money.

I firmly believe that the biggest day-to-day advantage of an SSD in a desktop computer is the vastly improved seek times. That order of magnitude leap from a 7200 RPM hard drive to an SSD is the difference you’ll be likely to notice. The other performance improvements are nice, but you’ll never notice them without a stopwatch.

If you’re still using an old-school spinning platter hard drive I think the Crucial M4 is a great value. It is quite speedy and well under a dollar per gigabyte.

(Not Quite) Native Linux Games for an Arcade Cabinet: Arcadia, Omega Race, Star Castle, Zektor and More

I recently saw a tweet from Rob Fearon that pointed me towards all of Sokurah’s awesome games over at tardis.dk. I’ve had fun playing Rob’s wonderfully colorful games, most of which have been on my arcade cabinet for a long time. That was a good enough reason for me to check out Sokurah’s games, and boy am I glad I did!

The list of games he’s made is quite large, and so far I’ve only gotten through most of the ones that use vector graphics. I sure do like vector graphics!

Every game from tardis.dk that I tried ran perfectly under Wine. I won’t be at all surprised if the ones I haven’t gotten to yet run just as well.

Most, if not all, of these games are remakes of classic games. They’re remakes of games from computers I never had the chance to see, so I don’t recognize many of them.

Arcadia is on the menu Star Castle on the big screen Zektor screenshot Omega Race 2009 screenshot

Arcadia

This is the one I’ve played the most. It looks easy, but I’ve been playing rather poorly. I died quite a few times before ever finishing the second level. I was very excited to see level three, though, and once I got there I seemed to be on level 5 before I knew it. I must be improving.

Arcadia very much reminds me of playing Parsec on my TI 99/4a when I was a kid. Parsec definitely didn’t use vector graphics, but your ship and some of the enemy ships were wire frames. In Arcadia the enemies attack vertically, in Parsec they attack horizontally. So maybe they’re pretty different. I don’t care, though; it still triggered a memory…

Omega Race 2009

I have no idea what the original Omega Race was like. This game looks like Asteroids with a big rectangular obstacle blocking the center of the screen. It definitely fits in nicely on the arcade cabinet.

Star Castle

This is the only one I recognized, and it is quite an awesome remake of the original. It looks great and plays exactly how you’d expect it to. I’m not sure what else I can say about this one, it is remade so well that anything I would say about this I would probably say about the original!

Zektor

This one is interesting. The first thing that popped into my mind when playing Zektor was “Asteroids as a scrolling shoot ‘em up.” The enemies come at your from the top and, mostly, move towards the bottom. You control a ship that steers and shoots just like in asteroids. Every few levels there is a boss inside a Star Castle-like fortress.

Mapping the Controls

Sokurah did an awesome job here. All the controls were simple enough to map to the arcade buttons. I was able to use a single mapping for all of his games. He even made it extremely easy to exit the games. When you hit escape it asks you to confirm that you would like to quit. He has yes and no mapped to left and right, which is incredibly convenient!

Team Fortress 2 - Linux Steam Beta

Native Steam client on Linux

It has been a while…

Steam tells me I haven’t played Team Fortress 2 since March 7th, so my abilities and my memories here may be a little rusty. The Steam Linux Beta seemed like a good excuse to play again, though!

Performance under Wine, eight months ago

The relevant specification of my laptop:

  • Nvidia GT 230M
  • Intel Core i7 2640QM (1.6ghz, 2.4ghz max turbo)

In March, under Wine, I had to run the game at 1280x720 to consistently get more than 30-40 frames per second or more. I remember a specific instance where the frames per second would drop under 20. On the “Upward” map, when waiting to spawn it sometimes shows you a view of pretty much the entire map. That view would drop to under 20 frames per second.

Native performance, today

With the native Linux Team Fortress 2 client I am able to play at 1920x1080 without any problems. I’m mostly seeing better frame rates than I had in March under Wine. I did check out that wide-angle view on the “Upward” map and I’m seeing 25 frames per second there now.

What else changed besides Wine vs Native?

This is exactly the same laptop I was using back in March. I’m running the 304.51 revision of the NVidia driver now; back in March I was likely running 290.x or 295.x.

Valve got multihead right!

I am running with a pair of 1080p LCD panels connected to my laptop. I expected it to do something stupid when I fired up Team Fortress 2. I was pleasantly surprised when it actually did the sanest thing possible.

It opened up a full-screen, borderless window on one of my displays. I had no trouble using my usual window manager hot keys to move the window over to the other monitor. I was completely free to click around the Team Fortress 2 menus or my other open windows. The game didn’t grab the cursor until I was actually actually playing. If I wanted to do something outside the game, all I had to do was hit escape to bring up the in-game menu.

This is exactly how full screen games should work.

Update: A recent update made full-screen support a bit less ideal. Now, when you click away to another window, you “full-screen” Team Fortress 2 is automatically minimized! I fixed this by adding export SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS=0 to my .zshenv file. Now I can comfortably poke around in my web browser in between rounds again!

I might have to put our Team Fortress 2 server back up!

Update: Use the 310.14 driver

I upgraded to the 310.14 driver last night. I installed it the lazy way (apt-get install nvidia-experimental-310). I’m now getting just shy of 70s frame per second on that wide-angle death view on “Upward” instead of 25!

Update: I started using the dx9frames configuration again. I seem to be too used to the lower quality graphics settings. With the default settings, I had kept mistakenly thinking that BLU team players that were on fire were actually on the RED team. I probably could have gotten used to this, but now my frame rates aren’t dipping down as low.

If you use the dx9frames configuration, I highly recommend that you flip the value of glow_outline_effect_enable from “0” to “1.” If you don’t, you’ll have an awful time using “The Scottish Resistance,” and you’ll never know where the cart is.

Cocktail Arcade Cabinet Upgrade: Part 2 - Early Impressions and Software Changes

It has been about two weeks since I hung the new television on the wall behind the arcade table. Most of what I’ve done since then is set up some scripts to automate the resolution and screen orientation settings, and also tweaking all the emulators and native games to use the correct resolutions and orientations.

I’ve run into some problems, but I’ve also found some solutions. One of the solutions is causing new problems. The upgrade has been fun, and I have some new ideas to implement later on.

WahCade menu on the big screen Mutant Mudds

Early impressions of the “hybrid” arcade cabinet

I really like it. It reminds me of playing while sitting on one of those big, red stools in a real arcade back when I was a bit too small to see the screen well from the ground.

I’ve spent quite a bit of time tweaking native game settings. I assumed that I’d get every game set up in just an hour or two. It didn’t work out that way because it is impossible not to play some of these games once you fire them up. I probably spent at least two hours replaying Cave Story Plus.

It does feel like I am cheating a bit. It feels less authentic, but I think I can live with that.

nvidia-settings, disper, and xrandr

At first I was using disper to control the resolution and which of the two displays were active. However, disper and nvidia-settings are unable to control the rotation of a single display, and I need to be able to run the “internal” monitor inverted. Preferably I should be able to rotate it on the fly, since the rotation results in a HUGE (4+ times) slowdown, and some games just won’t run fast enough that way.

I started out running Nvidia’s 295.49 drivers that ship with Ubuntu 12.04. I upgraded them to the 304.51 version because they are supposed to have proper support for xrandr 1.3.

They very nearly do. I can independently control the resolution and rotation of each display with xrandr. It won’t let me use xrandr to add modelines to either display. This is problematic because the internal monitor has a 1360x768 modeline and the external television has a 1280x720. There are a handful of resolutions they don’t share.

I can still set any resolution I can think of using disper. So now I’m using a disper to activate displays and set their resolution and I’m using xrandr to set the orientation of the internal display.

Another small difference between 295.49 and 304.51

The 295.49 driver was quirky with regard to the television. It would only drive it at 1920x1080 or 1280x720. Everything else would be scaled up. This made it easy to get aspect-correct scaling for modes like 640x480 and 800x600.

The 304.51 “fixed” this problem for me. It will happily drive the television at 640x480 or 800x600. I should be excited about this, but suddenly many of the games that I set up are now scaled incorrectly.

I’ll have to work on this one a bit more.

I’m all out of buttons

I’d like to be able to have some manual control over the video settings. I am planning on setting up a web interface to change some settings on the fly. That way, anyone here can tweak things from their tablet or phone.

I have a handful of possible uses for the web interface:

  • Change active video outputs and rotation (while games are running)
  • Adjust volume, toggle ambient arcade sound track
  • Kill the currently running game if it gets stuck
  • Power down the cabinet

A Couple of Useful Snippets from My Shell Config

I’ve been slowly and incrementally working on cleaning up my shell config. I’ve been procrastinating over my persist and forget system for quite a while now. I have it up and working here just fine, but I built it and its extra git repository in place. I need to automate the installation and configuration process and I would also like to make sure it isn’t likely to eat anyone’s file before I release it.

In the mean-time, though, I have been digging through my configuration and I’ve found a few gems that I would like to list here. I use these under zsh but I am pretty sure they will work fine under bash as well.

Quickly share files on the public Internet with Python and SSH

I see ‘python -m SimpleHTTPServer’ one liner all the time. By itself this one is pretty useless for me. I almost never need to share something with anyone on my local network. I use this function instead:

My webshare function
1
2
3
4
5
6
7
8
9
10
11
12
webshare () {
  local SSHHOST=patshead.com
  local SSHPORT=9999

  python -m SimpleHTTPServer &
  local PID=$!

  echo http://$SSHHOST:$SSHPORT | xclip
  echo Press enter to stop sharing, http://$SSHHOST:$SSHPORT copied to primary selection
  /usr/bin/ssh -R $SSHPORT:127.0.0.1:8000 $SSHHOST 'read'
  kill $PID
}

This does require you to have a server out on the Internet that you can ssh into. For my purposes, this fills a gap somewhere between a pastebin and something like Dropbox. I use it when I have a handful of files I want someone to take a look at.

A smarter tail command

I lifted this one from commandlinefu.com:

My tail function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
tail() {
  local thbin="/usr/bin/tail"
  local fc lpf thbin

  if [ "${1:0:1}" != "-" ]; then
    fc=$(($#==0?1:$#))
    lpf="$((($LINES - 3 - 2 * $fc) / $fc))"
    lpf="$(($lpf<1?2:$lpf))"

    [ $fc -eq 1 ] && $thbin -n $lpf "$@" | /usr/bin/fold -w $COLUMNS | $thbin -n
  else
    $thbin "$@"
  fi
}

I really like this one. This tail wrapper checks the size of the terminal window and makes sure it shows you just a bit less than a screen full of output. It even takes long lines into account.

Automatically managing a “scratch” directory

This function was heavily inspired by an entry on Marcin Kulik’s blog:

`` bash My function to create a new scratch directory function ns { local cur_dir="$HOME/tmp/scratch/current" local new_dir="$HOME/tmp/scratch/date +‘%s’`”

mv $cur_dir $new_dir mkdir $cur_dir cd ~/scratch echo “New scratch dir ready” }

I’m always creating new scratch directories to work in, so I really liked his idea of creating a function to help manage the process.

I didn’t change his implementation too much. The only real difference is that my symlink never changes. I’m just moving the old, real scratch directory out of the way and putting a new one back in its place.

Improving the Behavior of the cd Command in Git Repositories

Most people are probably aware that calling the cd command without any arguments will take you back to your home directory. If you’re anything like me, you probably do this dozens of times each day.

I also end up working in git repositories quite a bit, and when I am working in a git repository I regularly find myself wanting to return to the root of the repository. Most of the time I am not buried too deep and it just takes one or two cd .. commands to climb up to where I want to be.

This seemed a bit silly to me. I’d rather not have to count how many levels deep I am. I decided that it would be a good idea to overload the cd command. Now, if I am in deep inside a git repository and call cd with no arguments, it will pop me straight up to the root. If I am at the root of a git repository or not in a repository at all, it will take the usual action and return me to my home directory.

screenshot of gitcd in action

Here is the code:

git_cd function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
_git_cd() {
  if [[ "$1" != "" ]]; then
    cd "$@"
  else
    local OUTPUT
    OUTPUT="$(git rev-parse --show-toplevel 2>/dev/null)"
    if [[ -e "$OUTPUT" ]]; then
      if [[ "$OUTPUT" != "$(pwd)" ]]; then
        cd "$OUTPUT"
      else
        cd
      fi
    else
      cd 
    fi
  fi
}

alias cd=_git_cd

Update 2012-11-13: I found more code!

I found another small, helpful shell function that I’ve been using to augment the cd command. I have no idea where this little function came from. It has probably been in my config for quite a long time.

Screenshot of improved gitcd in action

If cd is given an existing file as the argument, this function will change to the directory containing that file. If not, it will just do what cd would normally do. I’m ever so slightly surprised that this function plays nicely with _git_cd!

Here is (very simple) the “cd-to-file” function:

cd to file function
1
2
3
4
5
6
7
8
9
cd () {
  if [[ -f "$1" ]]; then
    builtin cd $(dirname "$1")
  elif [[ "$1" == "" ]]; then
    builtin cd
  else
    builtin cd "$1"
  fi
}

Both the cd function and _git_cd function work using zsh or bash.

(Not Quite) Native Linux Games for an Arcade Cabinet: Mutant Mudds

I haven’t played this one much yet. I found this game in the Indie Royale Harvest Bundle, but my Google-fu couldn’t turn up any information on whether or not I’d be able to get it running on Linux using Wine, so I ended up trying it out for myself.

First level on the internal LCD The title screen The introduction

Getting it running under Wine

So far the game is running flawlessly under Wine. It took a bit of trial and error to get it up and running, though. I ended up trying quite a few different versions of Wine before it would work correctly. It ended up working when I tried version 1.5.9. When using versions 1.4.1, 1.5.3, and 1.5.16, it either failed to start or it just showed a black screen.

Knowing that part makes it easy. You just need to use winetricks to install d3dx9 and d3dcompiler_43. I ended up doing all that using Play On Linux. I also threw together my first POL installation script, MutantMudds.pol.

I’m sure it isn’t the most elegant script, but it is easy to use and it works. The steps should go something like this:

  • click on Tools -> Run a local script in the Play On Linux window
  • choose my MutantMudds.pol file
  • click install/ok/next/etc on any DirectX installer windows
  • choose MutantMudds_installer.exe when it asks for the installer
  • click through the Mutant Mudds installer

The controls

Mapping the game controls to the arcade control panel was easy. Mutant Mudds uses the arrow keys to move around, X to jump, Z to shoot, and escape to quit. It is one of those wonderful, arcade-friendly games that don’t require the mouse at all.

Early impressions

When I first saw the (very short) video on the Indie Royale site it made me think of Cave Story. After sitting at the controls for a couple of minutes and getting a better look at the graphics, I’m getting more of a Commander Keen vibe. That’s a very good thing. I have fond memories of playing most of the Commander Keen series.

Update: I just tested Mutant Mudds with Wine version 1.6 and it runs just fine. With any luck it will continue to run on later releases as well.

Mutant Mudds is definitely going to be an excellent addition to the arcade cabinet.