UPDATE 17 March 2013: I am placing this post into the public domain
so people are free to incorporate it into their existing files which may
be in the public domain already.
As I commented in my last post about tmux, tmux mouse mode left
some things to be desired. Namely, there are two problems.
First, it completely takes over the mouse. Meaning that you can no longer do a
simple “mark text and copy” operation on the native OS. There are patches over
this problem, like reattach-to-user-namespace, but that is only
helpful if you are running tmux on your Mac. I practically never do that,
because most of the usefulness of tmux for me is in leaving active sessions to
remote servers. I work on remote servers over ssh connections, detach from
tmux, and stick my laptop in its bag. I come back to the session later. That
would not be possible if tmux were running on my Mac, so I am almost always
running it remotely on a Linux server.
Second, there is the pane problem. If you turn mouse mode off, and try to copy
text in a pane that has another pane to its side, the terminal will just copy
across the boundary. iTerm has no idea that the pane boundary exists; it’s just
another character printed in the terminal window.
These days, I have mouse mode turned on by default in .tmux.conf. It’s just
too useful to not have it on. If my hand is already on the trackpad, switching
between windows or panes, or doing pane resizes, is very handy with the
pointer. It’s also usually much faster to do a mark/copy operation within tmux
by using the pointer.
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
But I do often want to do an OS-native mark and copy. So, I have defined two
hotkeys to make it easy to turn mouse mode on and off.
# Toggle mouse on with ^B m
bind m \
set -g mode-mouse on \;\
set -g mouse-resize-pane on \;\
set -g mouse-select-pane on \;\
set -g mouse-select-window on \;\
display 'Mouse: ON'
# Toggle mouse off with ^B M
bind M \
set -g mode-mouse off \;\
set -g mouse-resize-pane off \;\
set -g mouse-select-pane off \;\
set -g mouse-select-window off \;\
display 'Mouse: OFF'
UPDATE 20 July 2012: @aristidesfl points out that you don’t
need to bind anything for mouse mode disable in iTerm2, simply hold option
down and iTerm2 turns it off temporarily.
That makes it easy to switch between the two states (mouse mode on or off). But
there is still one nagging situation: I want to do OS-native copy and paste,
but it’s in a pane. Even with mouse mode off, things break because the terminal
does not know what a tmux pane is. Once again, key bindings come to the rescue.
These bindings (^B + and ^B -) are a “zoom” feature. Focused on a given
pane, ^B + will promote the pane to be its own window. Then you can do
OS-native mark and copy all you want, no panes to worry about. When you’re
done, just use ^B - to turn the window back into a pane, right where it was
before.
I’ve chosen to keep these two things separate, but with a little tinkering,
you can create a binding that does both operations together: zoom a window,
turn mouse mode off, and another binding to do the inverse.
As always you can find my current .tmux.conf file on GitHub.
UPDATE 17 March 2013: I am placing this post into the public domain
so people are free to incorporate it into their existing files which may
be in the public domain already.
UPDATE 16 July 2012: I have updated this post to reflect my current
keymaps, which I settled on after writing the original post.
As I’ve said before, I’m a huge fan of iTerm2. I am also
a huge fan of tmux, the terminal multiplexor. If you’re not familiar with
tmux, it’s conceptually the same thing as GNU screen, with some
differences, and (in my opinion) some advantages. For example:
In screen, each instance is its own completely separate process. With
tmux, the first time you run it, you start a server, but subsequent runs
will instantiate clients that connect to that existing server. Why does
that matter? Because it means you can lop a window off of one tmux
session and glue it onto another. It also means you can view the same
session from multiple clients simultaneously (say you left tmux attached
at the office, you can attach to that same session at home without
disrupting the session you left attached at work). You can even
share a session with someone else. All of that’s
possible because it’s all going on in the same server process.
tmux supports multiple panes within a window, where screen supports only
windows.
If you don’t set a window title, tmux will auto-set it for you based
on what you run in that window. So it might start as “bash” and change
automatically to “vim” or “top” or “tail” depending on what you run
inside. That is pretty handy to tell what’s going on in what window
even if you don’t take the time to set a name for it.
It so happens that the authors of iTerm2 are tmux users as well, and they have
integrated a tmux mode into iTerm2. It’s an early stage thing, so you have to
forgive it, but at this point it still has some drawbacks. I am not going to
talk about that integration much in this post, but I wanted to point out that
it exists, that I know about it, and explain why I don’t use it.
You can only connect iTerm2 to one iTerm2-aware tmux session at a time.
They communicate via a special protocol. In practical terms, this means
you “spend” a window for that channel. It sort of sits around lingering.
To be fair, they added an option to auto-hide it on connect so it goes
away by itself.
Because this is still under development, you currently have to run
the right version of iTerm2 with the right version of patched tmux.
That can be a headache if your server side is used by multiple people.
It also means an upgrade to iTerm2 sends you off to recompile tmux
before you can use it in integrated mode again.
For these reasons, I have set aside the iTerm2 tmux integration and I’m
just using regular tmux again. I’ll check it out again someday after it has
matured (and preferably been built into tmux mainline so I don’t have to
patch a copy myself).
But after using the integration, I found I was longing for easy hotkeys to
navigate around my windows and panes in tmux. (Using the integrated mode, you
use the iTerm-native hotkeys because it treats the tmux windows and panes as
native iTerm tabs and panes).
I was frustrated by this because in tmux you use a prefix key for everything,
so going to the next window means using Ctrl-B n and going to another pane
might be Ctrl-B H. You can remap a lot of things, but it’s never as easy as
native keys like Shift-Cmd-Right or similar that we are used to using on
Macs and PCs.
At first, I played with the tmux mouse mode. It’s actually pretty nice.
Assuming you send mouse events through to the server, tmux will recognize them
(if you turn on the appropriate options), allowing you to select windows and
panes using mouse clicks. You can even resize panes. Unfortunately, that comes
at a cost: it breaks using normal mouse selection to copy from iTerm2 window
into other programs on your Mac. Not good.
Then, I found “Send Hex Code.”
Angels rejoiced. Benjamins fell from the sky. My doctor told me to eat more
ice cream.
Send Hex Code is just an unassuming option in a pulldown in the iTerm key
mapping preferences. But when I saw it, I knew it was the solution to my
problem. The thing is, you can represent any ASCII character as a hex value,
and sending a sequence of ASCII characters is exactly what I needed to do.
My first goal was to navigate between windows. The default maps for that are:
12
^B n next window
^B p previous window
Let’s rewrite those as hex bytes.
12
0x02 0x6E next window
0x02 0x70 previous window
Next goal: navigate between panes in all four directions. This was stickier
because it involves arrow keys, but! arrow keys are just escape sequences. So
a few more hex bytes are all we need.
1
^B <arrow> move to pane in <arrow> direction
The ANSI arrow sequence is <Esc>[<direction> where direction is one of
[A, B, C, D] (mapped to [up, down, right, left]). Rewritten as hex:
1234
0x02 0x1B 0x5B 0x41 move to pane above
0x02 0x1B 0x5B 0x42 move to pane below
0x02 0x1B 0x5B 0x43 move to pane at right
0x02 0x1B 0x5B 0x44 move to pane at left
Lastly, I wanted to be able to resize any given pane in any direction using
key bindings. I added some bindings to ~/.tmux.conf (borrowing directional
keys from my favorite editor, Vim).
1234
bind-key J resize-pane -D
bind-key K resize-pane -U
bind-key H resize-pane -L
bind-key L resize-pane -R
Armed with all of my hex sequences, I headed to the iTerm2 preferences. Under
the “Keys” section, you can add new items to the global shortcut list. (You
can also do this in a profile’s key settings if you have a reason to not want
bindings to be available to all profiles.) I added the below sequences,
binding them to hotkeys.
1234567891011121314
Mac hotkey Hex sequence Purpose
Cmd-Left 0x02 0x1B 0x5B 0x44 Move to pane at left
Cmd-Down 0x02 0x1B 0x5B 0x42 Move to pane below
Cmd-Up 0x02 0x1B 0x5B 0x41 Move to pane above
Cmd-Right 0x02 0x1B 0x5B 0x43 Move to pane at right
Cmd-Opt-Left 0x02 0x48 Resize leftward
Cmd-Opt-Down 0x02 0x4A Resize downward
Cmd-Opt-Up 0x02 0x4B Resize upward
Cmd-Opt-Right 0x02 0x4C Resize rightward
Ctrl-Cmd-Left 0x02 0x70 Move to window at left
Ctrl-Cmd-Right 0x02 0x6E Move to window at right
But I am a Vim user. h,j,k,l have been mapped into my fingers for more
than a decade, and they are on the main keyboard, so I don’t need to
move my hand to the side. Why not map those as well?
1234567891011121314
Mac hotkey Hex sequence Purpose
Cmd-H 0x02 0x1B 0x5B 0x44 Move to pane at left
Cmd-J 0x02 0x1B 0x5B 0x42 Move to pane below
Cmd-K 0x02 0x1B 0x5B 0x41 Move to pane above
Cmd-L 0x02 0x1B 0x5B 0x43 Move to pane at right
Cmd-Opt-H 0x02 0x48 Resize leftward
Cmd-Opt-J 0x02 0x4A Resize downward
Cmd-Opt-K 0x02 0x4B Resize upward
Cmd-Opt-L 0x02 0x4C Resize rightward
Ctrl-Cmd-H 0x02 0x70 Move to window at left
Ctrl-Cmd-L 0x02 0x6E Move to window at right
The panel to enter each key binding into looks like this.
And this is what my final key map looks like.
Now I can move between tmux windows with Ctrl-Cmd-{direction}, move among
panes with Cmd-{direction}, and resize with Cmd-Opt-{direction}. It’s
really nice, and I can use Vim keys (H,J,K,L) or arrows.
(Yes, I am aware that this overrides certain keymaps. You will lose the
“Hide” hotkey, Cmd-H, but I never use that so I didn’t care. iTerm also
maps Cmd-{left,right} to navigate between tabs, but Cmd-{digit} and
Shift-Cmd-{left,right} will still work.)
Lastly, a few finishing touches for my tmux.conf. The colors I use
here assume Solarized Dark for the iTerm color scheme. They may
look awful with another color scheme (or they may look fine).
1234567891011121314151617
# Watch background windows for activity
setw -g monitor-activity on
# Make the active pane more visible
set -g pane-border-bg default
set -g pane-border-fg colour245
set -g pane-active-border-bg default
set -g pane-active-border-fg colour46
# Make the active window's name stand out
setw -g window-status-current-fg brightwhite
setw -g window-status-current-bg black
# Use color to indicate activity in a background window
# (Note this is inverted, fg means bg and vice versa.)
setw -g window-status-activity-fg white
setw -g window-status-activity-bg brightred
You can always find my current .tmux.conf file on GitHub.
Wouldn’t the better solution just be to have an app, or web app, that users pull up on their phone? That is: why should a restaurant pay to provide the hardware that most are already carrying with them?
No.
A geek would happily install an app on their phone. To us, it would seem
nifty, fun, and easy.
A regular person would walk in, find out they have to install an app on their
personal phone to order lunch, then walk out and find a restaurant whose
head was not up its own ass.
As a system administrator, op is one of my favorite tools. I have
explained why already, so I won’t go into it here.
If you clicked the op link above, you may have noticed that it goes to
a 404 page. (If you’re in the future maybe it works again; congratulations!)
At least, as of December 2011, it is a 404 page and it’s been that way for at
least a year now. The maintainer of the site (Alec Thomas) tells me that his
server crashed some time back, and he hasn’t had the time to get all of the
old content back online. His site mentions an upcoming daughter, and those of
you with kids are already nodding your heads, because you know exactly how
this story goes.
In any case, since there is currently no other place online to download this
code so far as I know, I dug up a tarball and mirrored it on GitHub.
You can get the latest code for op at tangledhelix/op.
My C skills are not up to par, so I am not currently planning to do anything
with the code except host a copy of it. If Alec never gets back to it, and
I decide to brush up on C in the future… well, we’ll see.
UPDATE: Dag Wieërs went to much more effort than I did and has set
up a new repository tagged with versions of op all the way back to
1.1 in 1995. It’s actually pretty amusing to see a release date in 1995 on
a GitHub page. I have removed my repo and will just point to his instead.
A bit of history to give some perspective on our modern issue of piracy (music
and movies):
A few centuries ago, the penalty for unauthorized copying was breaking on the wheel. It is a term we’re not very familiar with these days, but it was a form of prolonged torturous death penalty where the convict first had every bone in his body broken, and then was weaved into the spokes of a wagon wheel and set up on public display. The cause of death was usually thirst, a couple of days later.
Back then the issue was duplicating popular fabric patterns. Yes, that was
really a thing. And note that this didn’t happen to only a handful of
offenders. Sixteen thousand people suffered this fate. Over fabric patterns.
The brutality of our forebears never fails to amaze me.
But it’s the end result of this practice that I find the most fascinating:
Capital punishment didn’t even make a dent in the pirating of the fabrics. Despite the fact that some villages had been so ravaged that everybody knew somebody personally who had been executed by public torture, the copying continued unabated at the same level.
Another HUGE complaint I’d like to add to Brad’s list is when these websites draw a story out over 10 pages.
Welcome to the Internet — a place where physical pages don’t exist, and there’s no such thing as “no space left”. There is absolutely NO REASON for any story to span over more than one single page.
I wholeheartedly agree.
But the problem here isn’t cluelessness on the part of the editors. The problem
is that newspapers aren’t in the business of providing news, and they never
have been. They are in the business of gathering page views. They used to call
it circulation, and they used to sell half-page ads, classifieds, and coupon
inserts, but it’s the same game as it ever was (except less profitable).
Back in the 90s, I toured a local NBC affiliate’s offices with a friend who was
in the news business. Two things I heard that day have informed my opinion of
commercial news ever since.
My friend, a local news producer for many years:
How we decide what’s on tonight’s news: News is whatever I say it is.
Down in the bowels of the building was a room where two men watched a wall of
monitors. A videotape robot busily swapped tapes behind them. This room aired
the commercials.
This is the only room in the whole building that matters. What you think of as TV is just the stuff we cram in between commercials to keep you from changing channels.
Now and then you hear an old-timer rant about how we young people never sit
down and write a real letter anymore. (Young in this case is probably defined
as under 75.) We’re too busy with our email, our Twitter and Facebook, our IMs
and texts.
Clearly, they are technically correct. Nobody writes letters anymore. It’s
archaic, a relic of a bygone era. It’s simple economics. In the old days,
a letter was the best option to reach across a great distance and communicate
with someone. Technology has changed the equation; many better options now
exist.
Think of the oldest person you know. Consider life when they came of age.
That’s when we set our expectations of how the world is supposed to work. I’ll
use my wife’s grandmother as an example. She will turn 91 in a few weeks,
meaning she was born in the spring of 1920, in rural Poland. Since then she has
seen a lot, including the inside of a Nazi work camp.
What was life like when she came of age? Well, she lived in the country. She
probably walked everywhere. Maybe she had a bike, maybe not. There was no
Internet. There were no mobile phones. The television would not be invented
until she was eight years old, but I suspect she did not personally see one
until she emigrated to the United States after World War II. A trip to the next
town over would probably have been a major undertaking, let alone a long trip
(even one to a country next door, a fairly short trip by modern first-world
standards).
I am not saying she rants about people not writing letters; I can’t say I have
ever heard her say anything on the subject. But within her life experience,
a letter was the best option for most of the time. Only after she was entering
her 70s were better options coming into play: cheap long-distance rates and the
Internet.
As I age, I find myself thinking about the longevity of the information
artifacts we generate. In the beginning, I was mostly worried about digital
photos. How could I ensure they survived? Unlike film negatives, digital
storage technology changes quickly. Think fast: here’s a ZIP disk. Can you read
it? No? What about this 5.25” floppy? 3.5”? What is the likelihood that the
JPEG format will be readable by computers in common use when I am
a grandparent?
These days, I am concerned about digital artifacts as a whole. My life is
ever-increasingly digital, as it is with all of us. I have scanned and shredded
most of my file cabinet. I get my bills via email. I communicate with everyone
online, leaving no persistent trail (or so I hope). I haven’t used a film
camera in years. My magnetic-tape videocamera is in a bag somewhere, but my
Flip Mino and my iPhone shoot video all the time.
For the past ten years, I have been a member of Distributed Proofreaders,
whose mission is to help Project Gutenberg digitize public domain works for
safekeeping and distribution. We scan old books using OCR software, and then
the hive mind goes to work. I and many others proofread scanned text. Others
take the output from proofreaders and add formatting markup (italics,
footnotes, etc.). After several rounds of work, a completed ebook is handed off
to Project Gutenberg for publication. It is, for me, important work that I am
happy to help with. Time will destroy all old books eventually; I believe they
should be preserved for future generations.
I am currently working on a biography about William Cowper, a writer and
poet who lived during the latter half of the 18th century. As with many such
books, it is full of correspondence, which tells the story of his life. You get
a feel for who he was, how he lived, how his relationships worked. I had never
heard of William Cowper before I began scrutinizing these scans for errors, but
I now find myself fascinated with his story.
I wonder: will anyone be able to write such books about us in a hundred years?
How would they go about it? There will be so little left behind. Will your blog
still be running for someone to analyze? Where will your emails be accessible?
Your tweets? God help you, your Facebook photos from college?
They say the Internet never forgets, but I’m not so sure. I suspect that over
a long enough period of time, the Internet will in fact forget. It will forget
us all.