From the Canyon Edge -- :-Dustin

Monday, May 9, 2011

The Hardest Bug I've Ever Solved...

EDIT: In fact, I did not solve that bug in the first run.  As the comments note below, there was a flaw in my first solution.  However, with the help of some excellent readers, I've just released a better, more suitable solution.  This post has been updated accordingly, in order to provide accurate documentation of the functionality as released.
I'm oh-so-pleased to announce that I have solved the single bug I have thought longer and harder about than any other.  Ever.  Period.  The solution actually consists of some gorgeous, unprintable ASCII art...

(Skip to the recap at the bottom if you're not interested in perhaps the best blog post I've ever written while in the awesome nation of Hungary...)

From the very earliest days of the screen-profiles package, the first and foremost objection we encountered from traditional system administrators with the proposition that we (Ubuntu) might automatically drop you into a GNU Screen managed shell was, that eats your ctrl-a, which perhaps you have been using to go to the beginning of the line since the dawn of time.

Boy, have I struggled with that.  I mean, I have literally spent many, many nights awake, hacking away at screen-profiles, and then byobu trying desperately to satisfy two diametrically opposite camps -- one class of awesome sysadmins who are emacs-mode fiends and are forever-bound to pressing ctrl-a and moving their cursor to the beginning of the line, and a second class of equally awesome sysadmins who use the HOME key to go to the beginning of a line and totally rock their world using ctrl-a as the GNU Screen escape character.

How, oh how, do we ever make two camps of equally passionate, equally awesome people happy?  Talk about a proverbial Clash of the Titans...

But for the first time ever, I think Byobu 4.0 will actually solve this problem :-)  Please, hear me out...

The irony here is perhaps that 3+ years into my Ubuntu development career, I have circled all the way back to where I began, with the very first tool I wrote for Ubuntu, to scratch a very particular itch of mine.

In Ubuntu 8.04 (and older), the nano editor was the default editor used by various utilities (crontab, dch, etc).  This always bugged me about Ubuntu.  I mean, I knew why Ubuntu needed to default to nano, but I hated being treated like a Linux/UNIX newbie when I used Ubuntu.  So I wrote the Ubuntu utility select-editor.  And from 8.10 on, the first time you encounter a situation where you're required to interact with an editor, you're prompted to choose your preferred editor first.  I dare say that this has improved my life and preserved my sanity as an advanced Ubuntu command line user.

And here we are, back to byobu, screen, and the key that some of us love to hate, and the rest of us hate to love -- ctrl-a.

As of Byobu 4.0, it will now prompt you, the first time you press ctrl-a, and ask:

Configure Byobu's ctrl-a behavior...

When you press ctrl-a in Byobu, do you want it to operate in:
    (1) Emacs mode  (go to beginning of line)
    (2) Screen mode (screen's default escape sequence)
Note that:
  - F12 also operates as Screen escape in Byobu
  - You can press F9 and choose your escape character
  - You can run 'byobu-ctrl-a' at any time to change your selection

Select [1 or 2]: 

If you select (1), from this point forward, ctrl-a will behave in Emacs mode.  And if you enter (2), well you're off and running with ctrl-a in GNU Screen mode.

Sweet!!!  So now, perhaps you Emacs experts out there ask, "what is the Byobu/Screen escape character then, if I do select (1)"?

Helluva question, my friend.  Here's where we get into super techie fun...  :-)

As of Byobu 4.0, the universal escape character is now ctrl-^.  If you choose for ctrl-a to operate in GNU Screen mode, then, ctrl-a will actually throw a ctrl-^ into your Screen session, which actually triggers the escape mode (behaving exactly as before!)  Additionally, F12 has been remapped from it's previous binding to lock-your-terminal (sorry please use ctrl-a-x or ctrl-^-x now for screen locking...) to Byobu's and Screen's escape key.  And as always, you're oh-so-welcome to choose your own escape character at any time using F9 (byobu-config).

Wow.  How about that?  Okay, so to recap:
  1. Byobu 4.0+ users will be prompted the first time they press ctrl-a to select its behavior (and they can interactively reconfigure at any time by running byobu-ctrl-a)
  2. Byobu 4.0+ uses ctrl-^ (and optionally ctrl-a) as the escape sequence, which is always bound to F12, and may optionally be bound to ctrl-a or some other user configurable escape sequence.
Finally, a huge thanks to Clint Byrum (and so many others) for the final kick in the butt that pushed me over the edge to go and fix this once, and for all ;-)



  1. AFAICT, ASCII 16 is what you get when you press CTRL-P.

  2. Ctrl-P sends character 0x10. Emacs lovers who use Ctrl-P instead of the up arrow will hate it for the same reasons they hated Ctrl-A. Vim users who use Ctrl-P for the incredibly nifty keyword completion will perhaps have better reasons for their hate.

    The first 32 control characters can be entered using Ctrl with various letters and symbols (see the last column): Ctrl-@, Ctrl-A...Z, Ctrl-[, Ctrl-\, Ctrl-], Ctrl-^, Ctrl-_.

    At one point I went through all the letters of the alphabet, looking for an unused Ctrl combination to use as a screen escape key, and Ctrl-B was the only one I didn't already use for something else. I believe tmux, a GNU screen alternative/replacement, uses Ctrl-B by default, and I would recommend Byobu do the same. It's even mnemonic!

  3. I always use "escape ^^^^" in my .screenrc.
    That's ctrl-6, aka 0x1e, and I've never seen it used _anywhere_ else.

  4. Now if you can just get byobu in the default desktop install - maybe with some of your other system settings.... ;-)

    Just upgraded to 11.04. I really like Unity, think it was a great choice. Only took me three days to figure out I can still get my application list sorted by category folders though.

    Thanks for all the great work!

    (I think you should write up your byobu presentation for publication at

  5. Ctrl-^ is used in vim to switch to the last file you've edited (and back).

  6. Control-^ is no good on european layouts (portuguese at least),the ^ is available pressing shift-~.
    I never feel the need to change the default keys on screen/byobu, if i want do go to the begging of the line i press control-a-a . It's only one more key away and never had problems when using someone else's screen.

  7. "Finally, a huge thanks to Clint Byrum (and so many others) for the final kick in the butt that pushed me over the edge to go and fix this once, and for all ;-)"

    Not quite. Please see:

    I've already got my keybinding set to another key (ctrl-t), but byobu ignores .byobu/keybinding and keeps interrupting me!


Please do not use blog comments for support requests! Blog comments do not scale well to this effect.

Instead, please use Launchpad for Bugs and StackExchange for Questions.