lsd
is an alternative command for ls
that displays illustrative icons beside each of the items listed in the output. It also colorizes its output to make it even more clear what sort of files or properties the directory contains. However, the default color theme might not necessarily look readable on your terminal.
This short article shows how you can change the default coloring of the output of lsd
command.
Create the config file
Like many other command line tools, lsd
reads its setting from a simple config file. By default, lsd
would look for its config file inside the .config/lsd/
path of your system home directory. The file format should be of type yaml
(or yml
). On a linux distro, you can create this config file using the following command:
touch ~/.config/lsd/config.yaml
Add the config file content
There are a ton of options we can set in this config file. However, the one we’re interested in is the color
option. Go on with adding the following lines of code to the config.yaml
file.
color:
# When to colorize the output.
# When "classic" is set, this is set to "never".
# Possible values: never, auto, always
when: auto
# How to colorize the output.
# When "classic" is set, this is set to "no-color".
# Possible values: default, custom
# When "custom" is set, lsd will look in the config directory for `colors.yaml`.
theme: custom
Create colors file
Since there are many fields we can change the color for, we need to create another file specifically for this purpose.
touch ~/.config/lsd/colors.yaml
config.yaml
and colors.yaml
files are the only files you need to create. So, the path and file structure of the lsd
config directory would now look like this:
❯ tree ~/.config/lsd
/home/saeed/.config/lsd
├── colors.yaml
└── config.yaml
1 directory, 2 files
Add the fields and custom colors
Default theme color of lsd
uses the following colors for each field.
user: 230
group: 187
permission:
read: dark_green
write: dark_yellow
exec: dark_red
exec-sticky: 5
no-access: 245
octal: 6
acl: dark_cyan
context: cyan
date:
hour-old: 40
day-old: 42
older: 36
size:
none: 245
small: 229
medium: 216
large: 172
inode:
valid: 13
invalid: 245
links:
valid: 13
invalid: 245
tree-edge: 245
git-status:
default: 245
unmodified: 245
ignored: 245
new-in-index: dark_green
new-in-workdir: dark_green
typechange: dark_yellow
deleted: dark_red
renamed: dark_green
modified: dark_yellow
conflicted: dark_red
You can add the entire code above to colors.yaml
file and change the ones you like or just alter the options you’re intersted in and discard the other options. Keep in mind that in yaml
format the indentation matters. Also, you need to keep the parent node (lesser indented node) in place if you’re going to change one of its child nodes.
One weird thing about the content of this file (at least for me) was the use of color codes in a format I wasn’t already familiar with. These colors are expressed as single numbers from Xtrem-256color
colors. These 256 colors are the ones that your terminal can support. Use this Wikimedia page to find or select your desired color.
Finally, note that you DON’T need to restart the terminal or source the lsd
config files to effectively apply the changes you make. The changes will be immediatelly applied.
If you need to learn more about lsd
you can refer to its github page.