Clean lsd -l output with Icons but without Symlink Targets

ยท Gist

2 min read Original article โ†—

A robust one-liner and shell function to use lsd (LSDeluxe) with all its NerdFont-powered visual glory โ€” while hiding symlink targets (โ‡’ path).

It preserves icons, formatting, and works beautifully in scripts and aliases.

Perfect for minimalist terminal users who love beauty without unnecessary clutter.


๐Ÿง  What It Does

Step Purpose
script -q -c "lsd -l" Runs lsd in a pseudo-terminal (PTY) to preserve icons and formatting that would otherwise be lost in a pipe.
perl -pe 's/\r/\n/g; s/ โ‡’ .*//' Converts terminal line-overwrites into proper newlines, and strips symlink targets while preserving icons.
awk '!seen[$0]++' Removes duplicate lines caused by the overwrite behavior of PTYs.

โœ… One-Liner

script -q -c "lsd -l --color=always" /dev/null \
  | perl -pe 's/\r/\n/g; s/ โ‡’ .*//' \
  | awk '!seen[$0]++'

๐Ÿงฐ Shell Function

Add this to your ~/.bashrc, ~/.zshrc, or equivalent shell config:

dls() {
  script -q -c "lsd -l --color=always" /dev/null \
    | perl -pe 's/\r/\n/g; s/ โ‡’ .*//' \
    | awk '!seen[$0]++'
}

Then just run:

Enjoy a clean, symlink-target-free, icon-rich ls output.


๐Ÿ–ฅ๏ธ Requirements

  • lsd installed (dnf install lsd or via your package manager)
  • perl
  • awk
  • script (from util-linux, usually installed by default)
  • NerdFont-compatible terminal (for full icon goodness)

โœจ Credit

Discovered and refined by Michael Longval and ChatGPT (aka Peregrin).
It took ANSI necromancy, regex diplomacy, and a brave stand against the tyranny of \r.