Plugin catalog

categorizer

Labels each file with a category and subcategory based on its extension, in default and long listings.

↓ on this page

categorizer labels each file with a category and subcategory based on its extension, such as [Code] (Systems). Turn it on when a directory mixes file kinds and you want them marked in the listing.

lla -l --hide-group <dir> with only categorizer enabled.

Turn it on

# ~/.config/lla/config.toml
enabled_plugins = ["categorizer"]

Or run this once. It saves the same setting, so the plugin stays on until you run lla --disable-plugin categorizer.

lla --enable-plugin categorizer

Labels appear in the default and long views (formats = ["default", "long"]), and in the table view, which uses the long format. The default view shows the category only.

FieldTypeHolds
categorystringCategory name
subcategorystringSubcategory name, when one matches

Read them as JSON, where you also get an untyped category_color:

lla --json | jq '.[] | select(.name=="README.md") | .plugin'
{
  "subcategory": "Text",
  "category": "Document",
  "category_color": "bright_blue"
}

Or add them as columns. The plugin's label still prints after the row.

[formatters.table]
columns = ["name", "size", "field:category", "field:subcategory"]
┌───────────┬──────┬──────────┬─────────────┐
│ Name      │ Size │ category │ subcategory │
├───────────┼──────┼──────────┼─────────────┤
│ .git/     │ 384B │ -        │ -           │
│ README.md │   7B │ Document │ Text        │ [Document] (Text)
│ docs/     │ 160B │ -        │ -           │

Default rules

CategoryExtensionsSize limitSubcategories
Documenttxt, md, doc, docx, pdf, rtf, odt10 MiBText: txt, md. Office: doc, docx, xls, xlsx, ppt, pptx
Coders, py, js, ts, java, c, cpp, h, hpp, go, rb, php, cs, swift, kt1 MiBSystems: rs, c, cpp, h, hpp. Web: js, ts, html, css, php. Scripts: py, rb, sh, bash

Extensions match in any case. A file over its category's size limit gets no label, and neither does a file with an unknown extension or none.

Actions

Run an action with lla plugin run categorizer <action> -- <args>. Every action is interactive, so it needs a TTY and the default --output human. Running one also enables the plugin and saves that setting.

ActionArgumentsWhat it does
add-category<name> <color> <ext1,ext2> [description]Adds a category. Prints nothing on success.
add-subcategory<category> <subcategory> <ext1,ext2>Adds a subcategory to an existing category. Prints nothing on success.
list-categoriesPrints each category with its extensions and subcategories.
helpPrints usage.
lla plugin run categorizer add-category -- Images bright_magenta png,jpg "Image files"
lla plugin run categorizer add-subcategory -- Images Raster png,jpg

Example

lla -l --hide-group
-rw-r--r--   2B Nov 04 23:01 you a.JS [Code] (Web)
-rw-r--r-- 2.0M Nov 04 23:01 you big.rs
-rw-r--r--   2B Nov 04 23:01 you no_rule.xyz
-rw-r--r--   2B Nov 04 23:01 you small.rs [Code] (Systems)

big.rs has no label because it's over the 1 MiB limit for Code.

Settings

Rules live in ~/.config/lla/plugins/categorizer/config.toml, the file add-category and add-subcategory write to.

[[rules]]
name = "Data"
color = "bright_magenta"
extensions = ["csv", "parquet"]
description = "Tabular data"
size_ranges = [[0, 10485760]]
 
[rules.subcategories]
Text = ["csv"]

size_ranges is optional and counts bytes.