Using and Customizing zsh-syntax-highlighting With oh-my-zsh

| Comments

A screenshot of zsh-syntax-highlighting

I recently read about this nifty new real-time syntax highlighter: zsh-syntax-highlighting. It looked like it would be pretty handy, so I decided to try it out for a couple of weeks.

It is a bit too colorful out of the box

Too many things are highlighted by default for my tastes. Every correctly typed command, every file name, and every globbing character is highlighted in one way or another. I was especially unhappy with the underlined path names.

Some highlighting is really awesome

I may not like all the extra noise, but there are a few things that I’m finding to be very useful. Highlighting a misspelled command in red is very nice. It is nice to catch typos before trying to execute a command.

Highlighting reserved words should be pretty helpful. I use one-liner for loops all the time, but I’m very good at leaving out the do. Highlighting makes that slightly more, obvious but I sure wish the done would highlight red if it didn’t match a do. It does match pairs of brackets, though, so maybe I can get in the habit of using those instead of old bash-isms…

It also does a good job of quote highlighting. That will probably help me catch mismatched and unescaped quotes pretty easy.

Customizing colors when using oh-my-zsh

I had a bit of trouble here. I tried setting the color variables in a file in my ~/.oh-my-zsh/custom directory while loading zsh-syntax-highlighting as a plugin from my ~/.oh-my-zsh/plugins directory. When I did, this it was acting like the colors were not already defined. I thought this was a bit strange because oh-my-zsh loads plugins before it runs anything in ~/.oh-my-zsh/custom.

I didn’t investigate this very heavily. I just moved zsh-syntax-highlighting into my custom directory and loaded it manually.

Here’s what my zsh-syntax-highlighting configuration looks like:

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)

source $ZSH/custom/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

ZSH_HIGHLIGHT_STYLES[default]=none
ZSH_HIGHLIGHT_STYLES[unknown-token]=fg=red,bold
ZSH_HIGHLIGHT_STYLES[reserved-word]=fg=green
ZSH_HIGHLIGHT_STYLES[alias]=none
ZSH_HIGHLIGHT_STYLES[builtin]=none
ZSH_HIGHLIGHT_STYLES[function]=none
ZSH_HIGHLIGHT_STYLES[command]=none
ZSH_HIGHLIGHT_STYLES[precommand]=none
ZSH_HIGHLIGHT_STYLES[commandseparator]=none
ZSH_HIGHLIGHT_STYLES[hashed-command]=none
ZSH_HIGHLIGHT_STYLES[path]=none
ZSH_HIGHLIGHT_STYLES[globbing]=none
ZSH_HIGHLIGHT_STYLES[history-expansion]=fg=blue
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]=none
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]=none
ZSH_HIGHLIGHT_STYLES[back-quoted-argument]=none
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]=fg=yellow
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]=fg=yellow
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]=fg=cyan
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]=fg=cyan
ZSH_HIGHLIGHT_STYLES[assign]=none

Most of what I did was remove colors.

A Year of Native Linux Indie Games on My Arcade Cabinet - 2011

| Comments

Last January, or maybe a little while before then, I decided to set a small goal for myself and my arcade cabinet. I wanted to buy at least one native game for the arcade table each month.

I’ve written about some of these games already, but I haven’t managed to get to all of them yet. I figured that since it has been about a year since I set my goal, that it might be a good time to look back over the last twelve months or so and see how I made out.

Blocks that Matter Cave Story Mactabilis Squid Yes, Not So Octopus War Twat Voxatron

The list of games, nearly in order of purchase

There’s also a few games that I’m pretty excited about, but I’m traveling right now and it will be a while before I can install them on the arcade cabinet. I’m hopeful that they’ll all fit in very nicely there:

If my arcade table happened to have a different controller layout, then I’d be able to add a few more games to the list:

  • Droid Assault (blog, home)
  • Ultratron (blog, home)
  • Scoregasm (blog, home)
  • The Binding of Isaac (blog, home)

Those are just the handful of twin-stick shooters that I already own, and they would all be playable if I had built an upright arcade cabinet.

Are bundles considered cheating?

I’ve listed over 16 indie games I purchased for the arcade table during 2011. The majority of them were part of various Humble Bundles. If I’m counting actual individual transactions, then the count is closer to eight.

At least two of the Humble Bundles that I bought didn’t include any games that I could use on the arcade cabinet, and most of them came with duplicates… So I’m just going to split the difference and say that I did reasonably well last year.

Plans and hopes for 2012

The last couple of games I was waiting patiently for were Super Meat Boy and Voxatron. I don’t really have any specific games in mind that I’m waiting for next year.

I’d really like to get caught up with writing about the rest of last year’s games. I’m already at least a half dozen games behind. I’ll end up a full year behind by 2013 if I don’t work harder!

Native Linux Games for an Arcade Cabinet: Blocks That Matter

| Comments

Blocks that Matter

Another game from the Humble Voxatron Debut. This is an exciting bundle for my arcade cabinet! There are so many great games that fit quite well on an arcade cabinet: Voxatron, Gish, Blocks that Matter, and Jasper’s Journey.

Blocks that Matter

Blocks That Matter

Blocks That Matter is a fun little puzzle platformer from Swing Swing Submarine. I haven’t had a chance to get too deep into the game yet. I hope this isn’t a spoiler, but I’m up to the level where I have to out-run the giant blob guy that is chasing me.

The puzzling aspect seemed pretty simple, but I have a feeling that I’m being deceived… I think there’s already been two little secret boxes that I haven’t figured out how to get to already. In the game, you control a little robot, the Tetrobot. He is able to collect blocks of various materials (wood, sand, rock, etc.) by drilling through them or bashing them a few times with his head. He is able to place down groups of four blocks, in patterns shaped like Tetris pieces.

Some of the blocks, such as rocks, can support their own weight. Other blocks, like sand, will fall if they are not supported by another block or wall.

The controls

Blocks That Matter has my favorite kind of controls: every single thing in the game can be done with the keyboard. No mouse required for anything at all. That makes it so easy to drop it onto an arcade cabinet. All that was required was mapping my controller buttons to the correct keys.

I forgot to record a video…

… So all I have is this lousy picture:

Blocks that Matter

Native Linux Games for an Arcade Cabinet: Voxatron

| Comments

I am cheating a bit this time. I haven’t even played Voxatron on my arcade cabinet yet because the replacement power supply hasn’t arrived yet. The Humble Voxatron Debut will only be running for about two weeks, so I figured I should write about it sooner rather than later!

Voxatron

The controls

Voxatron maps very easily to the arcade controls. It uses the arrow keys for movement, z to jump, and x to shoot. The only other keys that need to be mapped will be enter and escape, for moving around the menus.

The game

Voxatron is a neat little 3D platform shooter. It feels a bit like Robotron with the addition of jumping. I’ve only played through a few levels, so I haven’t seen much of the game yet. I’m (impatiently) waiting to play it with the arcade controls!

The blocky retro-style graphics look awesome. I especially like that the little light guy’s head lights up when he is shooting. Voxatron will definitely be a welcomed addition to the growing collection of modern games on my arcade cabinet.

Update 2011-11-11: It is actually on the cabinet now!

The cabinet is back up and running and Voxatron looks amazing on there! I was very impatient and ended up playing through the whole “adventure” mode on my laptop long before the replacement parts for the arcade cabinet arrived. I know now that it is much easier to handle the hold-button-to-lock-shooting-direction control setup with the arcade controls than it is with the keyboard!

The Unfortunate Death of the Cocktail Arcade Cabinet

| Comments

I’ve been out of town for most of the last four months. One of the first things I did after “docking” my laptop was fire up the arcade cabinet. It booted right up and I was very happy and relieved to see that none of the hard drives had died while I was away.

I store a copy of my Duplicity backups on my arcade cabinet (it is also my home file server), so I kicked off my script that rsyncs the backups on my laptop over to the arcade cabinet. Less than a minute later, I hear the drives and fans in the arcade cabinet spin down…

I scratched my head, walked back over, and turned it back on. This time it shut off about half-way through the boot sequence. I got down on my back and crawled underneath. I felt like I was checking to make sure the oil filter on my DSM was snug (I’d had mine come loose before, the spindle screwed into the oil cooler could be problematic).

While I was looking up into the guts, I hit the power button. Things were pretty dark from that angle, and I didn’t think to bring a flash-light. I touched the CPU fan; it was spinning. I touched the power supply fan… It was not spinning.

At least it is an easy problem, just a dead power supply fan. I’m not surprised that it died; this power supply is probably over four years old by now.

The silver lining

My good friend Brian gave me one of his old video cards: an NVIDIA GeForce GTS 240. This card is a massive upgrade over the arcade cabinet’s current NVidia GeForce 6200LE, and tons more horsepower than I’m going to need. The dead power supply is lacking the 6 pin PCIe power connector required by the new card.

I ordered a new power supply. It should be here in a few of days. I’ll just have to survive without my home file server for a little while. This is so much better than coming home to a dead hard drive, or worse, TWO dead hard drives…

Update 2011-11-02:

The power supply arrived, but it didn’t fix the problem… It powered up for a minute or two and then shut itself down. I crawled underneath the cabinet again and started poking at things with my finger and noticed that the CPU heat sink was wobbling:

Broken plastic heat sink bracket

The little nub that holds the heat sink clip snapped off. I ordered a new bracket, so now I get to wait again.

I got to take a look at the old power supply now that it is out of the case. It actually has two fans, but I couldn’t see the second without removing the monitor. I tested it out by shorting pins 15 and 16 to start up the power supply. Both fans started right up.

I clearly remember sticking a “non conductive instrument” (aka a cheap ball point pen). I don’t recall hearing the usual “THWAP, THWAP, THWAP” sound that usually occurs when you do that with a spinning fan. I’m starting to think that I should be questioning my sanity!

Team Fortress 2 is Free to Play! Getting in-game Purchases Working with Linux and Wine

| Comments

Team Fortress 2 is now free to play, so I figured I would give it a try. I don’t really play many first-person shooters. For the most part, the only thing that seems to have changed much in the genre since the early days is the much-improved graphics. Game-play usually just involves using bigger and bigger guns to shoot more and more people.

I’ve always enjoyed games that involve cooperation. The last first-person shooter I played was Tremulous. In fact, a friend and I ran a semi-popular Tremulous server for a few years.

Team Fortress 2 shares many of the qualities I liked in Tremulous, but the community behind Team Fortress 2 is much more sizable. It also shares many of the same pitfalls, but overall I am definitely enjoying the experience.

Getting in-game purchases and Steam connectivity working is easy

The fix is very easy and I am a bit surprised at just how fragile this is. You just have to install the Lucida Console font (lucon.ttf). I just copied the font into ~/.PlayOnLinux/fonts on my system, since I’m using PlayOnLinux. If you’re not, you probably just have to drop a copy in ~/.wine/drive_c/windows/Fonts (or some similar location).

I didn’t install the font to fix the Steam connectivity. I installed it to fix the nearly unreadable font in the Team Fortress 2 console. I just happened to kill two birds with one stone.

We’re running a Team Fortress 2 server!

I’m not entirely sure how exciting this is, yet… Getting a crowd of people to play on a Tremulous server was easy. The community was small and it was pretty easy to differentiate ourselves from the crowd. This time, we’re just another (barely used) fish in a pond full of other nearly indistinguishable (also barely used) fish.

(Not Quite) Native Linux Games for an Arcade Cabinet: The Bundle of Wrong

| Comments

Squid Yes, Not So Octopus Squid Yes, Not So Octopus Squid and Let Die Squid and Let Die War Twat War Twat Squid Hardest Squid Hardest Squid Hardest GForce GForce GForce

Update 2013-04-29: The last time I tried to play Death Ray Manta using Wine, all I got was a white screen and some loud music. That was quite a few months and a number of Wine releases in the past. I gave it a try today using Wine 1.5.29 and it runs flawlessly! I didn’t even have to install libraries using winetricks.

I also figured I’d try some of the various SYNSO games, since they’ve been a little jittery on the arcade table lately. The ones I tried seem to be running fast and smooth under Wine again. I just had to install dsound and directmusic using winetricks.

I’ve been keeping an eye out for an arena shooter for my arcade cabinet. There are quite a few of them out there, but the majority of them require analog controls. I was pretty excited when I read about the Bundle of Wrong at OnlyLinuxGames.com.

The Bundle of Wrong is a pay-what-you-want-style bundle. My expectations were pretty low, I didn’t expect the games to run well under Wine. I was wrong; all the games in the bundle seem to run great under Wine.

Every game in the bundle looks quite awesome on my arcade cabinet. Unfortunately, for now, most of them run a bit slow on there. The good news is that I will be upgrading the video card soon. A good friend of mine is letting me steal one of his old video cards that is a few generations newer than the one currently installed in the cabinet.

The arena shooters: SYNSO:CE, Squid Harder:SE, and War Twat

All the arena shooters in the bundle share one thing in common: they are all extremely colorful and psychedelic. Especially War Twat, which also comes with a “Colour Blindness Edition” for old people like me who tend to lose track of the bullets in the rotating color palette.

I’ve enjoyed playing all three games, but I think my favorite is probably Squid Hardest. The arena feels a bit larger, and I really like the music in Squid Hardest. I have gotten that little tune stuck in my head a few times already!

A game with an awesome name: Squid and Let Die

I haven’t had a chance to play Squid and Let Die much. I have only gotten far enough to verify that it runs well on the cabinet. The short description from the Bagfull of Wrong website sums it up pretty well:

Squid And Let Die is a game. Collect the dots. Do not die. The board is a death trap. Fight inevitability.

The retro-style, mostly green graphics bring back fond memories of the green screen monitor of the Franklin Ace 1000 we had when I was a kid.

The Bundle of Wrong is fitting in well with my glowing collection of modern, retro-style games on my arcade cabinet.

Added in October, 2012: G:Force

I might be cheating a bit lumping G:Force in with the Bundle of Wrong, but I am going to do it anyway. I’ve only played it enough to know that it seems to run under Wine. It is being a little persnickety and sometimes freezing up on the arcade cabinet, but so far it is running perfectly on my laptop. I’ll have to compare my Wine settings between the two and see if anything is different.

Automatically Expanding zsh Global Aliases As You Type

| Comments

Animated demonstration of globalias

Update 2012-11-04: This page is now out of date. Since this entry was published, I cleaned this code up quite a bit. You should definitely check out the new entry.

I am not the first person to think of this idea. My notes seem to think that I originally found the idea on the zsh wiki and I stole the code I started with from hackerific.net.

What are global aliases?

Shell aliases let you condense a long-winded and/or hard-to-remember command down to a short, easy-to-remember word. Old-school shells will only match the alias if it is the first word in the command. Zsh lets you take that one step further by allowing you to define aliases that will be substituted no matter where they appear on the command line. These are global aliases.

Here is one of my global aliases that I use all the time:

1
alias -g G='|& egrep -i'

With this alias defined, these two commands are equivalent:

1
2
cat /proc/cpuinfo G cache
cat /proc/cpuinfo |& egrep -i cache

My problem with global aliases

When I look at a command line with a global alias, it isn’t always entirely clear to me what the command I am about to run is actually going to do. Am I sure my G alias has a -i switch? Does it use |& so that it will also grep stderr?

The existing solution

The handy script at hackerific.net sets things up so that as soon as you hit the space bar after typing the global alias, it is automatically expanded right there on the command line.

This is great for a couple of reasons. You never have to guess what code is hidden inside that alias. The full text of the command will be right there on the command line and in your history, so you’ll never be surprised. It also means you can go back and tweak the command a bit.

What I did differently

There is only one thing I didn’t like about the solution at hackerific.net. Instead of cleanly defining your global aliases with the alias command, you have to add your aliases into a hash table. His code uses that hash table to expand the aliases on the command line and also to create your actual global aliases (so that they still work at the end of the line).

I like that you only have to define them once, but I wanted to build the hash table out of the global aliases that are already defined.

I managed to parse the output of alias -g and stuff it into the hash table, but I wasn’t able to make it work without piping the output to Perl and sourcing the output back in. I tried to make it work with pure shell code, but none of the magic I came up with worked.

Deprecated globalias code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
typeset -A abbrevs

# Begin Ugly Hack

alias -g | perl -e "print 'abbrevs=('; while (<>) { s/^(.+?)='(.+)'/'\$1' '\$2' /g; s/'\\$/\\$'/g; print; } print ')';" > /tmp/cheater.zsh
source /tmp/cheater.zsh

# End Ugly Hack

globalias() {
   local MATCH
   LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9\-]#}
   LBUFFER+=${abbrevs[$MATCH]:-$MATCH}
   zle self-insert
}

zle -N globalias

bindkey " " globalias
bindkey "^ " magic-space           # control-space to bypass completion
bindkey -M isearch " " magic-space # normal space during searches

You can probably just paste this into your .zshrc near the end, after all your global aliases are defined.

oh-my-zsh plugin

I’m running my copy as an oh-my-zsh plugin. I haven’t uploaded it to github yet, though. I’d prefer to eliminate the ugly pipe-and-source lines first. I may have to upload it as is if I don’t get around to improving it, though.

You can download my plugin here. It is identical to the code above.

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

| Comments

I set a goal for myself early in the year. I would like to buy one Indie game for my arcade cabinet every month this year.

I’ve tried my best to find native Linux games, and there are plenty of awesome independent games that run natively on Linux. The problem is that the vast majority of these games require some sort of analog input, usually a mouse. My cabinet has no analog controls…

I have been keeping my eye out looking for Windows games that run well under Wine. There are quite a few Indie games that run very poorly under Wine, most of them were created using GameMaker.

I saw the Buy Games Not Socks and I immediately hoped that Mactabilis would run under Wine. I downloaded the demo and it ran absolutely flawlessly, so I immediately purchased the bundle.

It even runs well on my arcade cabinet with its ancient Nvidia 6200LE video card, even with the video flipped upside down. I do have to run it with the resolution set to 960x540, though.

Mactabilis

I was happy to learn that everything in the game can be controlled with the arrow keys and a handful of buttons. After mapping everything I would, need I still had one button left over on my six-button control panel.

Mactabilis

Mactabilis is an awesome side-scrolling shoot ‘em up. The first thing I noticed when I started playing was that the game felt backwards! I’m so used to my ship being on the left.

This was very easy to get used to. For half of the first level your ship is moving from left to right, but on the second half you reverse direction.

Mactabilis

Mactabilis has an interesting feature that I’ve never seen in a shoot ‘em up before. You can hit a button to move your ship between the foreground and the background layers. Enemies and obstacles seem to occupy one of the two layers.

If things get too crowded or dangerous in the current layer, you can just hit a button to move your ship into the opposite layer. Enemies in the other layer become transparent, blurry, and desaturated.

This is pretty neat, but I was constantly forgetting that this option exists…

Mactabilis

Mactabilis also seems to have a staggeringly huge number of weapons to purchase for your ship. I haven’t had time yet to get very far into the game, so I can’t really comment too much on this. I can say that the weapon screen has a seven-by-seven grid of weapons you can purchase. I can hardly wait to try some of them!

Updating the BIOS on an HP DV8T Laptop Without Windows (You Can’t)

| Comments

Nearly every piece of hardware in my laptop has worked fine, more or less, with Linux since I bought it early in 2010. There is only one minor bug that I am aware of, and it has been a minor nuisance the entire time: ACPI is unable to read the discharge rate of the battery.

This hasn’t really been that big of an issue for me. The battery only lasts about two and a half hours anyway, and there is no trouble reading the current charge left in the battery. I was hoping I’d eventually luck out and a kernel upgrade would magically start seeing the discharge rate. I’m up to 3.0-rc3, and still no luck there.

I didn’t have any reason to attempt to fix this problem until yesterday. I installed a copy of the latest and greatest development version of Powertop, version 1.98. The new version looks very promising. I was interested in trying the new calibration feature. It looks like it does things like cycle your LCD brightness, perform disk I/O, and stress the CPU a bit while monitoring power usage. This doesn’t seem to work so well if Powertop is unable to read the battery discharge rate.

My DV8T has a quad core i7 processor and the BIOS version was F.11. I bought two more DV8T laptops last summer, one for each of my parents. Theirs have Core 2 Duo processors. Luckily for me, I have a VPN between here and my parents’ house. I was able to ssh into my mother’s laptop and take a look around. She has BIOS version F.24, and ACPI has no trouble reading the discharge rate.

Updating the BIOS

I rarely update the BIOS on my machines. As far as I’m concerned, if it ain’t broke, don’t fix it. I decided that, in this case, if it seemed to be working on another very similar machine (with the same BIOS), that it was worth giving it a shot.

Here’s the rub. HP’s flash utility only runs on Windows. I don’t have Windows installed anywhere here at home. I probably have an old Windows XP CD squirreled away somewhere, but I have no idea where it is. I’m disappointed that they don’t have a DOS utility like most of their competition does. It isn’t a deal breaker. I’d still buy another laptop like this; I don’t often want to flash the BIOS on any of my laptops.

I tried a BartPE boot disk, and it blue screened. I ended up downloading the Windows 7 Enterprise 30 day trial from Microsoft and I installed it on an old spare laptop drive. This part of the journey is pretty uninteresting. Windows 7 installed just fine, and the BIOS flashed with just a few clicks.

Total waste of time

I’m up to BIOS version F.25. Here is the result:

wonko@zaphod:~$ cat /proc/acpi/battery/BAT0/state
present:                 yes
capacity state:          ok
charging state:          discharging
present rate:            unknown
remaining capacity:      4640 mAh
present voltage:         16434 mV
wonko@zaphod:~$ cat /sys/class/power_supply/BAT0/current_now 
cat: /sys/class/power_supply/BAT0/current_now: No such device
wonko@zaphod:~$               

Note the present rate: unknown and the No such device. I’m guessing this ACPI problem only exists on the Core i7 DV8T laptops. At least I got to see how much the Windows install process has (and hasn’t!) changed between Windows XP and Windows 7, for whatever that is worth…