Created
January 27, 2024 14:11
-
-
Save blackjack75/9b02acc18c330ae3ad813f0e273970ce to your computer and use it in GitHub Desktop.
Useful script for bash
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
#!/usr/bin/env zsh | |
# Use fzf and open file in text editor | |
vd() { | |
# folder, default to current directory | |
# depth, default to 1 | |
local dir=${1:-.} | |
local depth=${2:-1} | |
local selected_file | |
while true; do | |
selected_file=$(fzf --reverse --border --preview "if [ -d {} ]; then echo 'Folder: {}\nenter to cd'; else bat --style=plain --color=always {} ; fi" --preview-window=up:50%:wrap < <(find "$dir" -maxdepth "$depth")) | |
# cd to folder or open in editor | |
if [[ -n $selected_file ]]; then | |
if [[ -d $selected_file ]]; then | |
dir="$selected_file" | |
else | |
echo "$selected_file" | xargs "$EDITOR" | |
fi | |
else | |
break | |
fi | |
done | |
} |
Author
blackjack75
commented
Jan 27, 2024
- filters local dir using fzf
- uses bat for a nice preview
- open into $EDITOR
- cd if picked a folder
- first parameter is folder, second is depth (defaults to local directory, depth
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment