Skip to content

lessfilter reference ​

This page documents lessfilter's dispatch pipeline, rule scoring, pattern language, built-in categories, action rendering details, and [settings]. For an overview and override examples, see lessfilter.

How a file gets its command ​

When lessfilter is called for a preset and path:

  1. Rule assembly — lessfilter loads the rule list for the requested preset and appends the default preset's rules to the end.
  2. Metadata memoization — permissions, file type, MIME type, built-in category, and directory children (or sibling filenames) are inspected once and cached for the path.
  3. Scoring — every rule's pattern list is folded left to right to produce a score from 0 to 255. Score 0 never matches; score 255 short-circuits immediately; ties go to the first rule that reached the winning score.
  4. Execution — the winning rule's actions run according to its execution policy (All, Abort, or Until). If no rule scores above 0, lessfilter exits with code 2; if the winning rule's actions fail, it exits with code 1.

Rules ​

Each entry in a preset array under [rules] pairs an action list with a pattern list:

toml
[rules]
preview = [
  # Short form: [actions, patterns]
  [["sqlite"], ["application/vnd.sqlite3", "have:sqlite3"]],

  # Long form with execution policy
  [{ kind = ["mediainfo", "Metadata"], execution = "Until" }, ["cat:image", "have:mediainfo"]],
]

When a rule lists multiple actions, execution chooses how they chain:

PolicyBehavior
"All" (default)Run every action in order; succeed if at least one action succeeds
"Abort"Run actions in order and stop on the first failure
"Until"Run actions in order and stop after the first action that succeeds

Score modifiers ​

Each rule starts at score 0 and folds its patterns left to right using score modifiers prefixed before |:

PrefixModifierEffect when the pattern matches
>n|pat or n|patMax(n)Set score to max(score, n) (>|pat is Max(1))
<n|patMin(n)Set score to min(score, n)
+n|patAdd(n)Add n to score (+|pat adds 1, saturating at 255)
-n|patSub(n)Subtract n from score (-|pat subtracts 1)
^|pat or ^patReqKeep current score if matched; reset score to 0 if unmatched

Because patterns fold left to right, place positive-scoring patterns (cat:image, ext:sqlite) before Req patterns (have:mediainfo): a Req evaluated while the score is still 0 leaves the score at 0.

Prefix a pattern with ! (after any score modifier, as in 10|!cat:text or !have:bat) to invert the match. Prefix with \ to escape a literal leading modifier character.

When no score modifier is written, each pattern kind uses its default modifier:

Pattern kindDefault score modifier
application (app)Max(60)
glob:Max(50)
child:Max(50)
ext: (.ext)Max(30)
mime: (type/subtype)Max(20)
cat: (category:)Max(20)
*Max(0)
have:, type:, gitReq

Because ext: defaults to Max(30) while cat: defaults to Max(20), an ext: rule in default (30) will outrank an unmodified cat: rule in preview (20) unless you lower the default rule's score (1|ext:...) or raise the preset rule's score.

Patterns ​

PatternMatches
glob:<glob>Full path matching the glob
child:<glob>Directory entry (or sibling file when the target is a file) matching the glob
ext:<ext> or .<ext>Case-insensitive file extension (ext: with an empty value matches extensionless files)
mime:<type>/<sub...> or <type>/<sub...>Detected MIME type (* wildcards supported, such as image/*; directories have directory/*)
cat:<name>Built-in file category or custom [categories] group
application (app)Platform application (.app on macOS, .desktop / .AppImage on Linux, .exe on Windows)
*Any path
have:<prog>Executable <prog> is present on PATH
type:<ft>Filesystem or content type: f (file), d (directory), l (symlink), x (executable), b (block device), c (char device), s (socket), p (pipe), e (empty), or text (text MIME or detected text encoding)
gitPath inside a git work tree

Categories ​

f:st ships 33 built-in categories usable with cat:<name> (and with -t <name> in the Find view):

GroupBuilt-in categories
Media & Graphicsimage, video, audio, lossless, subtitle, playlist, font, model, diagram
Code & Textsource, configuration, markdown, text, build, compiled, temp
Documents & Datadocument, spreadsheet, presentation, ebook, academic, formula, database, metadata, geospatial, email
Archives & Systemcompressed, package, disk, rom, executable, crypto, other

You can define additional categories under [categories] in lessfilter.toml as lists of MIME strings or wildcards:

toml
[categories]
structured = ["application/json", "application/yaml", "application/toml"]

Any group defined under [categories] also becomes available to fs :: -t <group>.

Built-in action details ​

ActionBehavior by preset
DirectoryTree preview (liza :u2 in preview, :u in display, ::nav :a in extended, :sba in info, $FS_VISUAL / $VISUAL in edit)
TextDelegates to PG_IMAGE=false mm pager when mm is on PATH (handling bat highlighting, markdown, and PG_* variables), falling back to f:st's uncolored built-in minus pager otherwise (extended and info append Metadata; edit opens $FS_EDITOR / $EDITOR)
ImageInline graphics preview (extended adds header and Metadata; info shows Metadata; edit opens via system opener)
ApplicationResolves .app, .desktop, or .AppImage icon and renders it (liza :u2 fallback if no icon is found)
ExtractExtracts plain text from PDF and office documents with kreuzberg and streams it into the pager
MetadataPrints file -bL description plus character/word/line counts for text files (and liza :l in extended / info)
OpenLaunches the path with the OS default opener in every preset
HeaderPrints a dim italic path header before the rest of the rule's output
NoneNo-op that succeeds immediately

The editor and visualizer environment ​

When lessfilter runs from the TUI, matchmaker and f:st export context variables into the environment:

  • MM_PREVIEW_COLUMNS and MM_PREVIEW_LINES (COLUMNS and LINES) — dimensions of the preview panel.
  • HIGHLIGHT_LINE and HIGHLIGHT_COLUMN — 1-based match coordinates from the Search view.
  • Editor resolution (Text in edit) — checks $FS_EDITOR, then $EDITOR, falling back to the system opener. When HIGHLIGHT_LINE is set, f:st automatically passes the native line/column jump flag for nvim, vim, hx, kak, nano, micro, emacs, zed, code, codium, subl, kate, geany, and notepad++.
  • Visualizer resolution (Directory in edit) — checks $FS_VISUAL, then $VISUAL (expanding {} templates when present, or appending the directory path otherwise), without line-jump flags.

Images and graphics protocols ​

When rendering Image or Application inside the TUI preview panel, lessfilter emits an <MM_IMAGE> header with fit options, and matchmaker renders the image using the protocol configured under [preview.image] in mm.toml:

  • Auto-detection (protocol = "auto") — negotiates Kitty graphics, iTerm2 inline images, or Sixel, and falls back to Unicode halfblock characters ("characters") when no pixel protocol is supported.
  • Fit and filter options — horizontal_fit (default "contain"), vertical_fit (default "crop"), and scaling filter (default "triangle").
  • Direct CLI runs — when fs :tool lessfilter display runs directly in a terminal, Image delegates to mm image.
  • Paging vs. fullscreen viewing in the TUI — pressing ctrl-l (LFPaged(Preview)) pages the preview output in f:st's built-in pager and displays single-line metadata for images (press alt-i for more thorough metadata via info), whereas alt-l (LFPaged(Extended)) hands directly off to mm pager (PG_INTERACTIVE=true) to open the fullscreen image viewer.

Paging and headers ​

  • Text and mm pager — when mm is on PATH, Text delegates to PG_IMAGE=false mm pager (configured by matchmaker's pager.toml and PG_* environment variables such as PG_RAW, PG_FLAGS, PG_LANG, PG_FILENAME, PG_MARKDOWN, and HIGHLIGHT_LINE); when mm is absent, f:st falls back to its uncolored built-in minus pager.
  • Headers (--header and Header) — --header=true prints the file path header once before running any actions; --header=false suppresses all headers; omitting --header prints a header only when the winning rule includes the Header action (Text, Image, and Application in extended; Image and Application in info).
  • Highlighting — HIGHLIGHT_LINE is forwarded automatically to mm pager (which passes --highlight-line to bat).

Settings ​

History and recording ​

Under [settings] in lessfilter.toml, tracked_presets lists the presets that record a visit in the history database when invoked directly:

toml
[settings]
tracked_presets = ["edit", "alternate", "extended", "open"]

preview, display, and info are untracked by default because preview runs automatically on every cursor movement. Pass --record=true or --record=false on the CLI to override tracked_presets for a single call (the TUI passes --record=false and records completed foreground commands itself).

Detection settings ​

[settings] infer in lessfilter.toml controls how MIME types and file categories are detected:

ValueDetection method
"file_format" (default)Magic-byte and container inspection via file-format, populating both mime: and built-in cat:, with extension fallback
"infer"Magic-byte inspection via infer with extension fallback (mime: only)
"guess"Extension lookup via mime_guess only (mime: only)

Built-in cat:<name> patterns rely on the category produced by "file_format"; keep infer = "file_format" if your rules use cat:.

Diagnosing a resolution ​

fs :tool lessfilter <preset> --diagnose <path> prints the detected permissions, file type, MIME string, category, directory children, the winning rule and its action execution policy, the step-by-step [PASS] / [FAIL] score transitions for every pattern, and the final resolved command strategies.