fresort(1) General Commands Manual fresort(1)

fresort - sort lines by their usage frecency

fresort [options...] <frecency_file>

fresort is a filter which sorts lines passed to its input based on their usage frecency from a frecency_file (see FRECENCY section below). It puts lines which are not found in frecency file, followed by the lines ordered by their current frecency.

fresort also maintains frecency file and updates appropriate frecencies when used with --update switch, which counts as a usage "hit". In time, frecency files can grow with many historical entries which are no longer relevant. To preven this, fresort limits their number to the quantity controlled with --limit switch. On top of that, entries with frecencies approaching 0 are removed as well.

Input lines can be matched against their parts, similar to awk(1). This is controlled with --field and --field-separator switches. Even if only a certain field is compared, fresort always prints the whole original input line.

Frecency is a measure which combines usage frequency and recency. It prioritises entries which were used few times recently over the ones used many times long ago.

fresort uses exponential decay method to age frecency of entries in a frecency file. With this method one controls a haf-life of frecency, which is a time after which frecency decreases by half of its initial value. Half-life is controlled with --half-life (or short -t) switch.

fresort doesn't store half-life in frecency file so it can be changed freely in every invocation of fresort. However, using different half-life times updates and input filtering can yield unexpected results of decaying certain entries faster than than the other ones.

-u, --update=ENTRY
Instead of working in normal mode as input filter, count the "hit" for ENTRY and update its frecency in the frecency_file

-l, --list

Instead of working in normal mode as input filter, list entries in the frecency_file, sorted by their current frecency. This mode is most useful for debugging purposes with --with-score switch enabled.

-t, --half-time=HALF_TIME

Time in seconds after which original frecency rank decays by half (see: FRECENCY section).

-n, --field=N

Enable comparing against a particular field (column) of input line instead of a whole line. Columns are 1-indexed and 0 matches the whole line (which is a default behaviour).

-F, --field-separator=SEP

Field separator between columns when --field switch is active.

--reverse

Reverse the output order, putting the most frecent elements at the top. Contrary to non-reversed mode, fresort in reverse mode consumes the whole input before outputting anything.

--limit=N

Prevent frecency_file from uncontrolled growth and limit it to N entries of the most frecent entries.

--with-score

Output current frecency score together with a result line

--version

Show version of fresort.

-h, --help

Show help message.

#!/bin/sh
file=$(find . -type f -name '*.txt' | 
	fresort ~/.cache/files.fre | 
	fzf --no-sort --tac)
fresort -u "${file}" ~/.cache/files.fre
vim "${file}"

$ cat /etc/passwd | fresort ~/.cache/shells.fre -F ':' -n 7

Michał Góral <dev@goral.net.pl>

Source code: https://git.goral.net.pl/fresort.git

2024-12-21