Skip to content

Instantly share code, notes, and snippets.

@startakovsky
Last active June 15, 2023 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save startakovsky/70ea242d8a846a2e92b44b1c4a40a28b to your computer and use it in GitHub Desktop.
Save startakovsky/70ea242d8a846a2e92b44b1c4a40a28b to your computer and use it in GitHub Desktop.
This is a useful tool created with the help of GPT to get some good preview capabilities searching through files and folders.
## preview fzf
## prerequisites:
## - brew install fzf
## - (brew --prefix)/opt/fzf/install
pf () {
local dir=${1:-"."} # defaults to current directory if no argument is provided
local instructions="=== FILE SELECTION TOOL ===
Multi-select: Press TAB
Select all / Deselect all: Press CTRL+A
Exact match: Prefix with '
Fuzzy search by extension use '$', e.g. '.py$'
Copy output: 'pf | pbcopy'
Abort: CTRL+C or ESC
Finish: Enter"
local cmd="fzf --height 80% --header \"$instructions\" --multi --bind='ctrl-a:toggle-all' --preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || (exa -T {} || tree -C {})'"
local files
IFS=$'\n' files=($(eval "find $dir -type f -o -type d | $cmd"))
for file in "${files[@]}"
do
if [[ -n "$file" ]]
then
echo "$file"
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment