Skip to content

Instantly share code, notes, and snippets.

@mlongval
Created August 5, 2025 22:58
Show Gist options
  • Select an option

  • Save mlongval/321889a4c656ec597fc5c48870738fe9 to your computer and use it in GitHub Desktop.

Select an option

Save mlongval/321889a4c656ec597fc5c48870738fe9 to your computer and use it in GitHub Desktop.
Clean lsd -l output with Icons but without Symlink Targets

Clean lsd -l Output with Icons But Without Symlink Targets

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:

dls

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment