Last active
June 15, 2023 19:08
-
-
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.
This file contains 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
## 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