Sunday, June 29, 2014

Patching tmux(1)

Using tmux, you might have noticed that when running an application like 'ranger' you will get your window named as 'python'. That's not really descriptive, so I've looked if I can get the real name into my 'tmux' statusbar.

Tmux on linux uses '/proc/<pid>/cmdline' and extracts the last bit of path of the first field. That's the value to be the window name. Examining proc(5) filesystem, there is a field called 'comm' and corresponds to:

$ ps -p $PID -o comm=

From kernel documentation:

3.6 /proc/<pid>/comm  & /proc/<pid>/task/<tid>/comm
These files provide a method to access a tasks comm value. It also allows for
a task to set its own or one of its thread siblings comm value. The comm value
is limited in size compared to the cmdline value, so writing anything longer
then the kernel's TASK_COMM_LEN (currently 16 chars) will result in a truncated
comm value.

So I've made a patch.

It reads the 'comm' with fallback to 'cmdline' if it doesn't exit (not likely using newer kernel). If program name is longer than 15 characters it will be truncated.