Created
March 13, 2025 18:20
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # (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