Skip to content

Instantly share code, notes, and snippets.

@FractalWire
Created September 26, 2019 18:30
Show Gist options
  • Save FractalWire/639ce7835fb91a32f774780e11c55475 to your computer and use it in GitHub Desktop.
Save FractalWire/639ce7835fb91a32f774780e11c55475 to your computer and use it in GitHub Desktop.
The moving fuzzy file explorer powered by fzf
#!/bin/bash
# A simple script to make fzf a fuzzy-file explorer
old_folder=$(pwd)
cur_folder="$old_folder"
while true
do
ret=$(fd -t d --color=always \
| fzf --no-height \
--bind 'ctrl-h:abort+execute(echo "ACTION=LEFT")','ctrl-l:abort+execute(echo "ACTION=RIGHT" {})','alt-enter:abort+execute(echo "ACTION=EXIT" {})' \
--preview-window=right:50% --preview 'tree-git-ignore -L 2 -C {}')
code=$?
re='^ACTION=.*'
action=$([[ $ret =~ $re ]] && (echo $ret | cut -d ' ' -f 1 | cut -d = -f 2))
folder=$([[ $ret =~ $re ]] && (echo $ret | cut -d ' ' -f 2-) || echo $ret)
case $action in
LEFT)
cd ..
cur_folder=$(pwd)
cur_folder=$(test "$cur_folder" = '/' && echo '' || echo "$cur_folder")
;;
RIGHT)
cd "$cur_folder/$folder"
cur_folder=$(pwd)
;;
EXIT)
echo "$cur_folder/$folder"
break
;;
*)
test $code -eq 130 && echo "$old_folder" || echo "$cur_folder/$folder"
break
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment