Skip to content

Instantly share code, notes, and snippets.

@AdamGagorik
Created January 25, 2024 18:27
Show Gist options
  • Save AdamGagorik/65bc958f7c3d902ac18fb2c40706fbf4 to your computer and use it in GitHub Desktop.
Save AdamGagorik/65bc958f7c3d902ac18fb2c40706fbf4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Store the STDOUT of fzf in a variable
selection=$(find . -type d | fzf --multi --height=80% --border=sharp \
--preview='tree -C {}' --preview-window='45%,border-sharp' \
--prompt='Dirs > ' \
--bind='del:execute(rm -ri {+})' \
--bind='ctrl-p:toggle-preview' \
--bind='ctrl-d:change-prompt(Dirs > )' \
--bind='ctrl-d:+reload(find . -type d)' \
--bind='ctrl-d:+change-preview(tree -C {})' \
--bind='ctrl-d:+refresh-preview' \
--bind='ctrl-f:change-prompt(Files > )' \
--bind='ctrl-f:+reload(find . -type f)' \
--bind='ctrl-f:+change-preview(cat {})' \
--bind='ctrl-f:+refresh-preview' \
--bind='ctrl-a:select-all' \
--bind='ctrl-x:deselect-all' \
--header '
CTRL-D to display directories | CTRL-F to display files
CTRL-A to select all | CTRL-x to deselect all
ENTER to edit | DEL to delete
CTRL-P to toggle preview
'
)
# Determine what to do depending on the selection
if [ -d "$selection" ]; then
cd "$selection" || exit
else
eval "$EDITOR $selection"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment