Architecture Overview
Entry Point
Section titled “Entry Point”my-fzf.sh is the entry point. When sourced in .bashrc, it:
- Checks it’s running interactively — aborts silently if not
- Checks required dependencies — fzf, fd, rg, bat, zoxide. Aborts with error if any are missing
- Warns about optional dependencies — nvim. Continues loading if missing
- Defines helpers —
_frroot(),_fscope(),_fextassociative array - Sources all lib modules in order — core → scoped → variants → ext → ops → help
- Cleans up temp variables — unsets loop variables to avoid polluting the shell
Helpers
Section titled “Helpers”Three helpers power the command generation:
# Get git repo root, or fallback to current directory_frroot() { git rev-parse --show-toplevel 2>/dev/null || echo .; }
# Map scope letter to directory path_fscope() { case $1 in c) echo .;; r) _frroot;; g) echo "$HOME";; esac; }
# Map extension suffix to fd glob patternsdeclare -A _fext=( [md]="md" [ts]="ts tsx mts cts" [js]="js jsx mjs cjs" [json]="json jsonc" [sh]="sh bash zsh" [css]="css scss sass less" [svelte]="svelte" [astro]="astro" [html]="html htm" [toml]="toml")Command Generation
Section titled “Command Generation”Commands are generated by nested for loops that eval function definitions. This keeps the codebase compact — instead of writing 334 functions by hand, a few dozen lines of loops produce all of them.
Scopes (c, r, g) × Actions (f, d, n, b, z, g, gb, gn) × Variants (base, -h, -ni, -hni) × Extensions (md, ts, js, json, sh, css, svelte, astro, html, toml) × Operations (rm, mv, cp, rn)Design Decisions
Section titled “Design Decisions”- No config file — Extensions and scopes are hardcoded. Fork the repo to customize.
- No
$EDITORfallback — nvim is hardcoded. Users who prefer another editor fork the repo. - No fallback to
find/grep—fdandrgare required, not optional. This keeps the implementation simple. - Eval-based generation — Intentional. It mirrors the original dotfiles source and keeps the two in sync.
- Variable cleanup — All temp variables (
_s,_v,_e,_ef,_x,_ff,_rf,_f,_MYFZF_DIR) are unset after sourcing to avoid polluting the user’s shell.