Plugin catalog
code_snippet_extractor
Saves line ranges from source files as named snippets you can tag, search and export.
↓ on this page
code_snippet_extractor saves line ranges from source files as named snippets you can tag, categorize, search and export. Reach for it when you want to keep a piece of code around without leaving the terminal. It also shows a snippet count next to files in a listing.
Turn it on
Enable the plugin to see snippet counts in listings.
# ~/.config/lla/config.toml
enabled_plugins = ["code_snippet_extractor"]Or run this once. It saves the same setting, so the plugin stays on until you run lla --disable-plugin code_snippet_extractor.
lla --enable-plugin code_snippet_extractorThe count appears in the default and long views (formats = ["default", "long"]), and in the table view, which uses the long format. It comes from one integer field, snippet_count.
lla --json src | jq '.[] | select(.name=="main.rs") | .plugin'{
"snippet_count": 1
}Actions
Run an action with lla plugin run code_snippet_extractor <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.
| Action | Arguments | What it does |
|---|---|---|
extract | <file> <name> <start> <end> [context_lines] | Saves a line range as a snippet. Context defaults to 3 lines. |
list | [file] | Lists snippets, optionally for one file. |
get | <id> | Prints one snippet with its code. |
search | <query> | Finds snippets, then lets you select some to view, copy, tag or categorize. |
add-tags | <id> <tag>... | Adds tags to a snippet. |
remove-tags | <id> <tag>... | Removes tags from a snippet. |
list-categories | Lists categories with snippet counts. | |
list-by-category | <category> | Lists the snippets in a category. |
set-category | <id> <category> | Sets a snippet's category. |
export | <file.json> [id...] | Writes snippets to a JSON file, all of them if you name no IDs. |
import | <file.json> | Reads snippets from a JSON file and gives them new IDs, so importing twice creates duplicates. |
help | Prints usage. |
Snippets live in code_snippets.toml, in ~/Library/Application Support/lla/ on macOS and ~/.config/lla/ on Linux.
Example
lla plugin run code_snippet_extractor extract -- src/main.rs run_method 9 18Successfully extracted snippet 'run_method' from src/main.rs (lines 9-18) with ID: f09ca748-4942-426a-9d3b-d43a01b417c9lla plugin run code_snippet_extractor add-tags -- f09ca748-4942-426a-9d3b-d43a01b417c9 rust
lla plugin run code_snippet_extractor listAdded tags #rust to snippet
Found snippets:
→ [f09ca748-4942-426a-9d3b-d43a01b417c9] run_method [rust] #rustlla srcengine.rs
main.rs [1 snippets]Settings
~/.config/lla/plugins/code_snippet_extractor/config.toml sets one thing that takes effect: tag in its [colors] table. Other keys in that file do nothing in 0.6.6.
Permissions
filesystem = ["read:selection", "read:user-path", "write:user-path"]: it reads source files and writes the export files you name. clipboard = true for the copy step in search.