-
-
Save codegenerator-cz/158ece3e4eed1bd34759fb3f687409e3 to your computer and use it in GitHub Desktop.
The moving fuzzy file explorer powered by fzf
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
#!/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