DEV Community

Cover image for Solarized + tmux + ls + bold text
Zach Whaley
Zach Whaley

Posted on

Solarized + tmux + ls + bold text

How I got Solarized, tmux, ls, and bold text to work together.

Running ls from a Solarized tmux session returns a bunch of gray directories and files, instead of the distinguishable colors we would expect.

"Bright" blue

This is because ls uses "bright" colors for directories and certain files, but Solarized has overridden these "bright" colors with its base colors.

But I don't want "bright" colors, I want bold text. So I spent some time googling and hacking on config files, and I eventually got what I wanted!

ls to print colored directories and files with bold text 😀

As a preface, I honestly have no idea why this worked 😕

My Setup

I've only tested this within my own setup, so if it doesn't work for you, sorry ☹️

Setup

Solarized

No changes here, thankfully.

I just set my terminal's colors to the beautiful Solarized colors as instructed by Ethan.

tmux

You must be using tmux 2.2 or above. I noticed this did not work on tmux 2.1.

$ tmux -V
tmux 2.2
Enter fullscreen mode Exit fullscreen mode

My TERM environment variable is set to xterm-256color by default. I'm unsure if that is something terminator is doing or Fedora, but it is what it is.

In my .tmux.conf file, I set the default-terminal option to screen-256color.

set -g default-terminal screen-256color
Enter fullscreen mode Exit fullscreen mode

Finally, I used the -2 option when opening tmux to force tmux to assume the terminal uses 256 colors. I created an alias for tmux which includes this

alias tm='tmux -2'
Enter fullscreen mode Exit fullscreen mode

Bold text

I created a .dir_colors file in my home directory using dircolors.

dircolors -p > ~/.dir_colors
Enter fullscreen mode Exit fullscreen mode

This file defines all the color codes ls will use when printing files and directories.

I then used the ANSI SGR parameter code 38 to specify colors from the extended 256 colors.

For example: From dircolors, the config to set directory colors, DIR, was set to 1;34, which results in a bright(1) blue(34) color.

DIR 1;34
Enter fullscreen mode Exit fullscreen mode

But, as I've mentioned, the Solarized "bright blue" is not actually blue, but a gray hue.

Using the 38;5 ANSI code, I was able to specify the bold(1) ANSI 256(38;5) color blue(4), NOT bright!

DIR 1;38;5;4
Enter fullscreen mode Exit fullscreen mode

Bold blue

And there you go!

You can find the rest of my .dir_colors file, along with all my home directory config files on GitHub.

http://zachwhaleys.website/2017/01/19/solarized+tmux+ls+boldtext/

Top comments (1)

Collapse
 
egmontkob profile image
egmontkob • Edited

Indeed traditionally SGR 1 is unclear whether stands for bold, bright or both of them. The introduction of 256-color palette (and later even direct RGB true colors in many terminal emulators) clarify that bold is the one that makes sense. For legacy reasons, you cannot suddenly remove the brigtening effect, plenty of utilities's output would look ugly. However, the new semantics (bold only) is used in most terminal emulators if the 256-color escape sequences are used, e.g. 38;5;4 instead of 34.

gnome-terminal 3.28 (vte 0.52) introduces a new configuration option, designed especially for Solarized users, that makes bold (SGR 1) never to switch to the bright counterpart. Hopefully Terminator will add support too: bugs.launchpad.net/terminator/+bug....