Crates.io | goldfish |
lib.rs | goldfish |
version | 0.1.0 |
source | src |
created_at | 2020-04-28 01:33:58.37646 |
updated_at | 2020-04-28 01:33:58.37646 |
description | Command-line LRU cache for better filesystem navigation |
homepage | |
repository | https://github.com/nwtnni/goldfish |
max_upload_size | |
id | 234837 |
size | 26,863 |
This is a basic LRU cache backed by an append-only log file. I use it along
with cd
, neovim
, and fzf
, in order to have recently-viewed
directories and recently-edited files available via fuzzy search. It's meant to
be a more transparent alternative to tools like z
, and therefore doesn't
try to predict or rank anything. It also supports multiple caches via the
--cache
flag.
goldfish
implements first-class support for caching directory and file paths, in
the sense that it will a) canonicalize paths and b) check if the path
is a file or directory before storing it in the cache. This means the paths
should be valid from any working directory, so you can always cd
to or edit them.
This behavior can be enabled by passing the --type
(-t
) flag to goldfish put
, e.g.
> goldfish --cache files put --type file src/foo.rs
> goldfish --cache files put --type file src/
> goldfish --cache files get
/home/nwtnni/projects/example/src/foo.rs
goldfish
is fairly low-level and meant to be called from a shell script or alias.
For example, here's the Bash function I use to change directories:
# Open a directory, list its contents, and cache its path.
#
# If no directory is provided, then use `fzf` to select from the directory cache.
o() {
if [ -z "$1" ]; then
dir=$(goldfish --cache directories get | fzf)
if [ ! -z "$dir" ]; then o "$dir"; fi
else
cd "$1" && ls && goldfish --cache directories put --type dir "$1"
fi
}
More detailed options can be viewed with the --help
flag, i.e. goldfish --help
.
Currently requires a Rust installation, and is only available from either:
> cargo install goldfish
> git clone https://github.com/nwtnni/goldfish.git
> cargo build --release
> ./target/release/goldfish
Log entries are just the data followed by a u16
length footer. This allows
append operations to blindly write to the end of the file. Reading the log is
done backwards, starting at the last two bytes and seeking back to get each
piece of data, which allows us to avoid reading the whole file and efficiently
build the set of most recent entries.
(I'm not entirely sure what performance impact reading a file backwards has on, say, caching or prefetching. This would require some benchmarking.)
There are several articles stating that goldfish actually have decent memory spans, contrary to the popular myth, but I couldn't find many sources. The closest I found was this radio transcript and this science project.