-
-
Save bbrodriges/482e7a9b1a01e03afef3cee5f4de36f8 to your computer and use it in GitHub Desktop.
ls-like fzf file manager
This file contains hidden or 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/sh | |
| CURDIR=$PWD | |
| if [[ -n "$1" ]]; then | |
| CURDIR=$1 | |
| fi | |
| clear | |
| while :; do | |
| SELECTED=$( | |
| LC_COLLATE=C ls -lah --color=always $CURDIR \ | |
| | grep -E -v '^total \d+$' \ | |
| | fzf \ | |
| --reverse \ | |
| --ansi \ | |
| --cycle \ | |
| --multi \ | |
| --no-scrollbar \ | |
| --no-info \ | |
| --no-border \ | |
| --no-input \ | |
| --pointer='' \ | |
| --marker='*' \ | |
| --prompt='' \ | |
| --color='bg+:reverse,fg+:reverse:bold,hl:-1,hl+:-1:reverse' \ | |
| --expect='enter,left,right,E,D' \ | |
| --bind "shift-down:page-down" \ | |
| --bind "shift-up:page-up" \ | |
| --bind "/:show-input+pos(0)" \ | |
| --bind "esc:deselect-all+clear-query+hide-input+search()" \ | |
| --bind "space:toggle" \ | |
| --bind "ctrl-a:select-all" \ | |
| | awk '{print $NF}' | |
| ) | |
| SELECTED=($SELECTED) | |
| [[ ${#SELECTED[@]} -eq 0 ]] && break | |
| KEYPRESS=${SELECTED[0]} | |
| ITEMS=(${SELECTED[@]:1}) | |
| [[ ${#ITEMS[@]} -eq 0 ]] && break | |
| case $KEYPRESS in | |
| "left") | |
| cd .. || break | |
| ;; | |
| "right") | |
| if [[ ${#ITEMS[@]} -eq 1 ]] && [[ -d ${ITEMS[0]} ]]; then | |
| cd ${ITEMS[0]} | |
| else | |
| $EDITOR ${ITEMS[@]} | |
| fi | |
| ;; | |
| "enter") | |
| if [[ ${#ITEMS[@]} -eq 1 ]] && [[ -d ${ITEMS[0]} ]]; then | |
| cd ${ITEMS[0]} | |
| else | |
| $EDITOR ${ITEMS[@]} | |
| fi | |
| ;; | |
| "E") | |
| $EDITOR $CURDIR | |
| ;; | |
| "D") | |
| printf "%s\n" "${ITEMS[@]}" | |
| read -p $'\nAre you sure you want to delete these files? (y/N) ' -n 1 -r | |
| echo | |
| if [[ $REPLY =~ ^[Yy]$ ]]; then | |
| rm -f ${ITEMS[@]} | |
| fi | |
| clear | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| CURDIR=$PWD | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment