Skip to content
Gokcehan edited this page Mar 19, 2022 · 20 revisions

This page is outdated and it will be removed soon. See "Icons" section in the documentation for more information.

You can enable icons by enabling icons option (i.e. set icons). By default there are only two icons defined for files (i.e. πŸ—Ž) and directories (i.e. πŸ—€). If these icons are not displayed properly, you may need to change to a different font with a more complete unicode coverage.

Icons for different files can be configured using $LF_ICONS variable. Syntax for this variable is the same as $LS_COLORS variable. You can define icons for different file names and types using this variable.

Below is an example configuration that you can use as a start. You need to define and export this variable in your shell configuration file (e.g. ~/.bashrc). You may want to keep it in a separate file and source it in your shell configuration file (e.g. [ -f "/path/to/icons" ] && source "/path/to/icons"). You also need to have Nerd Fonts installed in your system for the following to work.

export LF_ICONS="\
tw=:\
st=:\
ow=:\
dt=:\
di=:\
fi=:\
ln=:\
or=:\
ex=:\
*.c=:\
*.cc=:\
*.clj=:\
*.coffee=:\
*.cpp=:\
*.css=ξ˜”:\
*.d=:\
*.dart=:\
*.erl=:\
*.exs=:\
*.fs=:\
*.go=:\
*.h=:\
*.hh=:\
*.hpp=:\
*.hs=:\
*.html=:\
*.java=:\
*.jl=:\
*.js=:\
*.json=ξ˜‹:\
*.lua=:\
*.md=ξ˜‰:\
*.php=:\
*.pl=:\
*.pro=:\
*.py=:\
*.rb=:\
*.rs=:\
*.scala=:\
*.ts=:\
*.vim=:\
*.cmd=:\
*.ps1=:\
*.sh=:\
*.bash=:\
*.zsh=:\
*.fish=:\
*.tar=:\
*.tgz=:\
*.arc=:\
*.arj=:\
*.taz=:\
*.lha=:\
*.lz4=:\
*.lzh=:\
*.lzma=:\
*.tlz=:\
*.txz=:\
*.tzo=:\
*.t7z=:\
*.zip=:\
*.z=:\
*.dz=:\
*.gz=:\
*.lrz=:\
*.lz=:\
*.lzo=:\
*.xz=:\
*.zst=:\
*.tzst=:\
*.bz2=:\
*.bz=:\
*.tbz=:\
*.tbz2=:\
*.tz=:\
*.deb=:\
*.rpm=:\
*.jar=:\
*.war=:\
*.ear=:\
*.sar=:\
*.rar=:\
*.alz=:\
*.ace=:\
*.zoo=:\
*.cpio=:\
*.7z=:\
*.rz=:\
*.cab=:\
*.wim=:\
*.swm=:\
*.dwm=:\
*.esd=:\
*.jpg=:\
*.jpeg=:\
*.mjpg=:\
*.mjpeg=:\
*.gif=:\
*.bmp=:\
*.pbm=:\
*.pgm=:\
*.ppm=:\
*.tga=:\
*.xbm=:\
*.xpm=:\
*.tif=:\
*.tiff=:\
*.png=:\
*.svg=:\
*.svgz=:\
*.mng=:\
*.pcx=:\
*.mov=:\
*.mpg=:\
*.mpeg=:\
*.m2v=:\
*.mkv=:\
*.webm=:\
*.ogm=:\
*.mp4=:\
*.m4v=:\
*.mp4v=:\
*.vob=:\
*.qt=:\
*.nuv=:\
*.wmv=:\
*.asf=:\
*.rm=:\
*.rmvb=:\
*.flc=:\
*.avi=:\
*.fli=:\
*.flv=:\
*.gl=:\
*.dl=:\
*.xcf=:\
*.xwd=:\
*.yuv=:\
*.cgm=:\
*.emf=:\
*.ogv=:\
*.ogx=:\
*.aac=:\
*.au=:\
*.flac=:\
*.m4a=:\
*.mid=:\
*.midi=:\
*.mka=:\
*.mp3=:\
*.mpc=:\
*.ogg=:\
*.ra=:\
*.wav=:\
*.oga=:\
*.opus=:\
*.spx=:\
*.xspf=:\
*.pdf=:\
*.nix=οŒ“:\
"

A config file

Some users may not like having to fill their bashrc' with extrenuous icon declarations. While there has been some talk about adding a configuration file (see #286), current users can hack together a config-file using an extra sed process. For example see here.

LF_ICONS=$(sed ~/.config/diricons \
            -e '/^[ \t]*#/d'       \
            -e '/^[ \t]*$/d'       \
            -e 's/[ \t]\+/=/g'     \
            -e 's/$/ /')
LF_ICONS=${LF_ICONS//$'\n'/:}
export LF_ICONS

This opens the file at ~/.config/diricons and uses sed to strip comments (a comment is defined as any amount of leading whitespace from the start of the line plus # character) and trailing whitespace. This script then treats the first word of each remaining line as an icon pattern and the rest of the line as the icon value. The last sed expression above appends an extra trailing space to each icon (just because most of the icons I use are wide-spaced, you may want to remove this if you find the spacing extrenuous). Lastly we use bash substitution to (LF_ICONS=${LF_ICONS//$'\n'/:}) to replace each trailing linebreak with a PATH seperator. The end result is a string matching the LF_ICONS format.

WARN: If you're using a non-bash like shell the substitution will fail. You can instead replace it with an extra tr '\n' : call.

For example if ~/.config/diricons looks like this:

foo bar
baz      bag
     # hello world
# can you believe it
bam # boom

LF_ICONS will end up looking like foo=bar:baz=bag:bam=# boom.

Clone this wiki locally