Will Roe’s blog

A variety of geekery » Archives

Custom Colours for Tmux

I have been using a rather dull Solarized (by Ethan Schoonover) tmux theme for a while now, it looks like this:

I tried to tweak the colours to vaguely match the magenta powerline theme of an Emacs theme called moe-theme (Emacs doesn’t work well with the powerline-patched fonts, so the unicode arrows look funny):

I have acheived something close and it looks like this (you need powerline-patched fonts for the unicode characters to work):

Here is the final config for the status colours and content (I decided to ditch the segment that shows my username, since it’s always the same and I know who I am). This goes in your ~/.tmux.conf:

1
2
3
4
5
6
set -g status-fg black
set -g status-bg colour231
set -g status-left '#[fg=colour234,bg=colour162,bold] ❐ #S #[fg=colour162,bg=colour231,nobold]⮀'
set -g window-status-format "#[fg=black,bg=colour231] #I #[fg=black,bg=colour231]#W "
set -g window-status-current-format "#[fg=colour231,bg=colour141]⮀#[fg=colour231,bg=colour141,bold] #I ⮁ #W #[fg=colour141,bg=colour231,nobold]⮀"
set -g status-right '#[fg=colour162,bg=colour231]⮂##[fg=colour231,bg=colour162] %H:%M %d-%b-%y'

Emacs themes and tmux have different colour palettes. Here’s how moe-theme specifies some powerline colours for the modeline:

1
(set-face-attribute 'powerline-active1 nil :background "#ffafff" :foreground "#ff1f8b")

Which is easy enough - they are simply hex colour codes, the same as can be used in CSS. However tmux uses 24-bit xterm colour codes (for a generous total of 256 colours). In order to map between them and find the closest colour I found a handy python script which you can call with a hex code (e.g. python colortrans.py ff4ea3) and it’ll print the nearest xterm colour code. If you call the script with no arguments it’ll print a mapping table of xterm colour codes to hex codes, so you can tweak the value you’re using. Or you can simply use this colour chart. One thing that stalled my progress for a while was I kept writing [fg=color183,bg=color213] sort of thing and tmux is unusual in using the French/British spelling of colour, which is unusual in programming. At least it’s otherwise straightforward, unlike bash color codes which look like somebody fell on the keyboard.

Css-mode Broken on Debian With Emacs 24

If you get an error like this

Symbol's function definition is void: apropos-macrop

When editing CSS files with Emacs on Debian (testing or unstable at the time of writing), then this is because the package css-mode includes code that no longer works with Emacs version 24 and has been abandoned (emacs contains its own css-mode).

The solution is simply to uninstall css-mode:

sudo apt-get remove css-mode

That’s it.

Fast String Interpolation in ClojureScript

In my previous post on string interpolation in Clojure, I benchmarked << from core.incubator and it proved both useful and performant. But can this useful macro be used from ClojureScript? Yes.

Add core.incubator to your dependencies in project.clj of your ClojureScript project:

1
2
3
4
(defproject some-project "1.0.0-SNAPSHOT"
  :dependencies [...
                 [org.clojure/core.incubator "0.1.3"]
                 ...]

Now you can require the strint macros in your ClojureScript source (e.g. in src/cljs/app/core.cljs):

1
2
(ns app.core
  (:require-macros [clojure.core.strint :as strint]))

Now you can use the fast string interpolator thus:

1
2
3
4
5
6
7
8
(enable-console-print!)

(let [name "Ethel Smyth"
      profession "Composer"
      born 1858]
  (println
   (strint/<< "The person named ~{name} works as a ~{profession}
and was born in ~{born}")))

That’s it!