DEV Community

Cover image for Tip 5: Replacing ls with exa
David McKay
David McKay

Posted on

Tip 5: Replacing ls with exa

Rust ... slowly but surely, all applications are being rewritten in Rust.

My next few tips will cover a few of these :)

Exa

Exa is an ls replacement written in Rust. As they say in their README:

with more features and better defaults

What does it look like?

Output from Exa

Alt Text

Pretty shiny, eh?

Things worth noting:

  1. Colours that distinguish directories, files, and executable files
  2. Colours for permissions, owners, and size of file
  3. Git status of each file in long output

Trees Everywhere

When working with code, it can be pretty nice to get a tree style look at the repository. Exa surpasses expectations here too.

First, here are a few aliases I have configured:

# ls
TREE_IGNORE="cache|log|logs|node_modules|vendor"

alias ls=' exa --group-directories-first'
alias la=' ls -a'
alias ll=' ls --git -l'
alias lt=' ls --tree -D -L 2 -I ${TREE_IGNORE}'
alias ltt=' ls --tree -D -L 3 -I ${TREE_IGNORE}'
alias lttt=' ls --tree -D -L 4 -I ${TREE_IGNORE}'
alias ltttt=' ls --tree -D -L 5 -I ${TREE_IGNORE}'
Enter fullscreen mode Exit fullscreen mode

Let me explain:

  • --tree - Enables Tree display
  • -D - Show directories only (Useful for large trees)
  • -L n - How many levels deep to display
  • -I ${TREE_IGNORE} - This omits/hides common vendor directories, as defined in the variable above the aliases

Here's a short asciinema of me using the lt, ltt, and lttt aliases:

Top comments (2)

Collapse
 
silvanocerza profile image
Silvano Cerza • Edited

I used exa for more than a year but recently I decided to ditch it in favor of ls with .dircolors. I've lost some colors, like in the permission columns, but ls is much more reliable than exa.

It happened that exa would sometimes not print a file even if it was present, running it just a second later would show it, kinda impossible to reproduce, probably a concurrency issue. That was pretty annoying but the tipping point for me was when it always crashed on a specific directory, ls was obviously working correctly.

I think this kind of rewrites in Rust will gain more popularity when they'll start being reliable like their original counterpart.

Collapse
 
eggbean profile image
eggbean • Edited

I made this wrapper script so that you can use the same switches as ls, so you don't need to learn any new ones.

gist.github.com/eggbean/74db77c4f6...