frec
frec is a frecency-based tool for managing file weights, inspired by zoxide.
Getting Started
# Add a file to track (first time: rank=1, within 1 hour: *4 = score 4)
# Query files (sorted by score, higher = more frequent)
# Query with scores shown
# Add again to increase rank
# Use e command (after running: eval "$(frec init zsh)")
Table of Contents
Introduction
What if your terminal could remember not just where you've been, but what you've done?
zoxide changed how we navigate directories—its frecency algorithm learns your habits and makes jumping between folders feel like magic.
But here's the thing: why should this magic be limited to cd?
The frecency algorithm—tracking both frequency and recency—is surprisingly universal. It works for anything you use repeatedly. That's what frec does: it extracts this intelligence and applies it to arbitrary strings, especially file paths.
Pipe it into fzf, and suddenly you have:
- Smart file editing — your most-used files appear first
- Project hopping — jump between projects you actually work on
- Command recall — surface commands you use most often
- Anything you can dream up
Meet frec_editor
frec_editor is a shell script that proves what's possible with frec + fzf.
Here's a rough idea of how it works:
| | &&
By combining frec with fzf via a pipe, you can intelligently choose which files to edit based on your personal usage patterns.
Install
# Install frec
# Install shell integration and frec_editor
Usage
Add a path
Add or update a file's weight in the database:
Query paths
Query files from the database:
Shell initialization
Generate shell initialization script:
Features
Multi-table Management
frec supports multiple tables to organize different types of files:
defaulttable: for general files- Custom tables:
--table=editor,--table=project, etc.
Frecency Algorithm
The ranking algorithm considers both frequency and recency (same as zoxide):
- rank: number of times the file has been accessed via
frec add
| Last access time | Frecency |
|---|---|
| Within 1 hour | rank * 4 |
| Within 1 day | rank * 2 |
| Within 1 week | rank / 2 |
| Otherwise | rank / 4 |
JSON Storage
All data is stored in ~/.local/share/frec/db.json:
Shell Interaction
Zsh
Add the following to your ~/.zshrc:
Then you can:
- Press
Ctrl+eto open interactive file selection with fzf - Or type
eand press Enter
After selecting a file, it will be added to the editor table and opened with $EDITOR.
Bash
Add the following to your ~/.bashrc:
Press Ctrl+e to open interactive file selection with fzf.
Usage
The e command supports two modes:
- Interactive mode (no arguments): Press
Ctrl+eor typeeand press Enter to open fzf for file selection - Direct mode (with path):
e ~/code.cppdirectly opens the file and trains its weight
Examples:
Each time you open a file through e, its frequency score increases, making it rank higher in future interactive selections.
Yazi Integration
You can integrate frec with Yazi file manager to track file access frequency.
Setup
-
Ensure
frec_editoris in your PATH (already installed viafrec install) -
Add the following to your
~/.config/yazi/yazi.toml:
[]
= [
{ = 'frec_editor "$1"', = true, = "Edit with frec", = "linux" },
]
- Restart Yazi
Now when you open a file in Yazi, it will automatically be added to the editor table with increased frequency score.
License
MIT © m1dsolo