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:
- Rule assembly —
lessfilterloads the rule list for the requested preset and appends thedefaultpreset's rules to the end. - Metadata memoization — permissions, file type, MIME type, built-in category, and directory children (or sibling filenames) are inspected once and cached for the path.
- Scoring — every rule's pattern list is folded left to right to produce a score from
0to255. Score0never matches; score255short-circuits immediately; ties go to the first rule that reached the winning score. - Execution — the winning rule's actions run according to its execution policy (
All,Abort, orUntil). If no rule scores above0,lessfilterexits with code2; if the winning rule's actions fail, it exits with code1.
Rules
Each entry in a preset array under [rules] pairs an action list with a pattern list:
[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:
| Policy | Behavior |
|---|---|
"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 |:
| Prefix | Modifier | Effect when the pattern matches |
|---|---|---|
>n|pat or n|pat | Max(n) | Set score to max(score, n) (>|pat is Max(1)) |
<n|pat | Min(n) | Set score to min(score, n) |
+n|pat | Add(n) | Add n to score (+|pat adds 1, saturating at 255) |
-n|pat | Sub(n) | Subtract n from score (-|pat subtracts 1) |
^|pat or ^pat | Req | Keep 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 kind | Default 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:, git | Req |
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
| Pattern | Matches |
|---|---|
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) |
git | Path 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):
| Group | Built-in categories |
|---|---|
| Media & Graphics | image, video, audio, lossless, subtitle, playlist, font, model, diagram |
| Code & Text | source, configuration, markdown, text, build, compiled, temp |
| Documents & Data | document, spreadsheet, presentation, ebook, academic, formula, database, metadata, geospatial, email |
| Archives & System | compressed, package, disk, rom, executable, crypto, other |
You can define additional categories under [categories] in lessfilter.toml as lists of MIME strings or wildcards:
[categories]
structured = ["application/json", "application/yaml", "application/toml"]Any group defined under [categories] also becomes available to fs :: -t <group>.
Built-in action details
| Action | Behavior by preset |
|---|---|
Directory | Tree preview (liza :u2 in preview, :u in display, ::nav :a in extended, :sba in info, $FS_VISUAL / $VISUAL in edit) |
Text | Delegates 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) |
Image | Inline graphics preview (extended adds header and Metadata; info shows Metadata; edit opens via system opener) |
Application | Resolves .app, .desktop, or .AppImage icon and renders it (liza :u2 fallback if no icon is found) |
Extract | Extracts plain text from PDF and office documents with kreuzberg and streams it into the pager |
Metadata | Prints file -bL description plus character/word/line counts for text files (and liza :l in extended / info) |
Open | Launches the path with the OS default opener in every preset |
Header | Prints a dim italic path header before the rest of the rule's output |
None | No-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_COLUMNSandMM_PREVIEW_LINES(COLUMNSandLINES) — dimensions of the preview panel.HIGHLIGHT_LINEandHIGHLIGHT_COLUMN— 1-based match coordinates from the Search view.- Editor resolution (
Textinedit) — checks$FS_EDITOR, then$EDITOR, falling back to the system opener. WhenHIGHLIGHT_LINEis set, f:st automatically passes the native line/column jump flag fornvim,vim,hx,kak,nano,micro,emacs,zed,code,codium,subl,kate,geany, andnotepad++. - Visualizer resolution (
Directoryinedit) — 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 scalingfilter(default"triangle"). - Direct CLI runs — when
fs :tool lessfilter displayruns directly in a terminal,Imagedelegates tomm image. - Paging vs. fullscreen viewing in the TUI — pressing
ctrl-l(LFPaged(Preview)) pages thepreviewoutput in f:st's built-in pager and displays single-line metadata for images (pressalt-ifor more thorough metadata viainfo), whereasalt-l(LFPaged(Extended)) hands directly off tomm pager(PG_INTERACTIVE=true) to open the fullscreen image viewer.
Paging and headers
Textandmm pager— whenmmis onPATH,Textdelegates toPG_IMAGE=false mm pager(configured by matchmaker'spager.tomlandPG_*environment variables such asPG_RAW,PG_FLAGS,PG_LANG,PG_FILENAME,PG_MARKDOWN, andHIGHLIGHT_LINE); whenmmis absent, f:st falls back to its uncolored built-inminuspager.- Headers (
--headerandHeader) —--header=trueprints the file path header once before running any actions;--header=falsesuppresses all headers; omitting--headerprints a header only when the winning rule includes theHeaderaction (Text,Image, andApplicationinextended;ImageandApplicationininfo). - Highlighting —
HIGHLIGHT_LINEis forwarded automatically tomm pager(which passes--highlight-linetobat).
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:
[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:
| Value | Detection 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.