2014-01-19

How to resize tmux windows using OS X terminal

A while back I pointed out a blog post by someone else, which described how to get C-left and C-right working in tmux and OS X. Now I noticed that I cannot resize windows in tmux. This is because tmux seems to expect xterm keys for C-arrow. The xterm keycodes for the arrow keys are:

  • left key: ^[[D
  • right key: ^[[C
  • up key: ^[[A
  • down key: ^[[B
  • C-left: ^[[1;5D
  • C-right: ^[[1;5C
  • C-up: ^[[1;5A
  • C-down: ^[[1;5B

I can now configure OS X terminal to send those key codes, and tmux works fine. However, other apps running in tmux will break, because they don't expect to get xterm key codes. I found a workaround in the ArchWiki, which suggests to create your own terminfo entry. I will try that and report back here.

Update: The solution is adding two lines to the ~/.tmux.conf file:

set -g default-terminal "xterm-256color"
setw -g xterm-keys on                   

Update 2: And here is my OS X Terminal.app configuration:

Update 3: And a very last update... It seems that tmux does not support bce (background color erase), which xterm does. This is a problem for progams like htop, vim, or mc. You will see rendering errors, if you do not fix this.

So you need to make your own terminfo file and own terminal type, called xterm-256color-nobce. You can do this on the command line:

pi@raspberrypi ~ $ infocmp xterm-256color | sed 's/bce, //' | sed 's/xterm-256color/xterm-256color-bce/g' > xterm-256color-nobce

This will create a new terminfo source file, which does not advertise the bce feature. You can install this with the following command:

pi@raspberrypi ~ $ sudo tic ./xterm-256color-nobce

This makes the terminal type xterm-256color-nobce available. After this, change your ~/.tmux.conf once again, to use the new terminal type per default:

set -g default-terminal "xterm-256color-nobce"

Update 4: To make the Ctrl+Arrow keys also work in regular OS X Terminal, you need to edit or create ~/.inputrc to contain this:

# xterm keys for skipping a word
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word

The "1;" variant is otherwise not recognized by GNU readline on OS X.

2014-01-02

How to setup an OpenWRT router as a WiFi bridge to an Ethernet router

You can use an OpenWRT router or access point to connect WiFi enabled devices to a router, which only has wired Ethernet. For this to work, I am assuming you already have an access point or router running OpenWRT, in this case version 12.09, Attitude Adjustment.

Log into your router, using the LuCi frontend, and go to the Network/Interfaces tab:


There you should see your LAN device. Edit it to have an appropriate IP address from your local subnet. Most often your network will be 192.168.0.0 and your existing router will have the IP 192.168.1.1. But your mileage may vary...

Lets put in a static IP address, so we can find our router in case something goes wrong. Also make sure to set the netmask (in this case 255.255.255.0), gateway and DNS server (both probably should point to your router, 192.168.1.1).


Now go to the Physical Settings tab. Here, it's important to check "Bridge interfaces" and to select both the ethernet adapter, most likely eth0, and the wireless network. One of the ethernet devices will say "wan", if your are using a router instead of an access point for this. You don't want that device.


Hit "Save & Apply" when you are ready. And be sure to have the de-bricking guide ready, if something goes wrong...

2014-01-01

How to run tmux via ssh instantly

With my Raspberry Pi, what I do very, very often is this:

localhost$ ssh raspberrypi.local    # Here I already type the next command and wait a while
raspberrypi$ tmux attach

This is all well and good, but sometimes the Pi is down, and I will attach to one of my local tmux sessions. Very annoying. Instead you could try to do this:

localhost$ ssh raspberrypi.local tmux attach
not a terminal

Well, that did no good. So a look at the man-page of ssh or a quick search reveals this gem:

localhost$ ssh raspberrypi.local -t tmux attach

This allocates a pseudo terminal, which is needed by tmux to function correctly. This is also done by ssh, if no command is given, but a login shell is spawned.