Skip to content

Instantly share code, notes, and snippets.

@androidStern
Created March 13, 2025 18:20
Show Gist options
  • Select an option

  • Save androidStern/350487daef57ada7ecca6d6062101af9 to your computer and use it in GitHub Desktop.

Select an option

Save androidStern/350487daef57ada7ecca6d6062101af9 to your computer and use it in GitHub Desktop.
(F)uzzy C(at) select files and directories and send contents to stdout w/ filename prepended (deps: fd, fzf, bat)
# (F)uzzy C(at) select files and directories and send contents to stdout w/ filename prepended (deps: fd, fzf, bat)
function fat() {
# fd is much faster than find and excludes hidden files by default
fd --type file --type directory --exclude "node_modules" | \
sort | \
fzf \
--multi \
--preview 'if [ -d {} ]; then tree -C -L 1 {} | head -50; else bat --color=always --style=header {} | head -50; fi' \
--bind "tab:toggle,shift-tab:toggle+up,ctrl-space:toggle-preview" \
--header 'Tab: select | Ctrl-Space: toggle preview' | while read -r selection; do
if [[ -d "$selection" ]]; then
fd --type file . "$selection" | xargs -I{} bat --decorations=always --style=header "{}"
elif [[ -f "$selection" ]]; then
bat --decorations=always --style=header "$selection"
fi
done
}
# usage `fat | pbcopy`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment