Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 76 lines (65 sloc) 2.17 KB
#!/bin/bash
IMG_DIM=250x250
SOURCES=$(echo ~/{downloads,projects,docs,notes})
# append image preview markup
function process_files {
while read -r line; do
case "$line" in
*.png|*.jpg|*.jpeg|*.gif) FILES_="$FILES_"$'\n'"IMG:$2$line\t$line";;
*) FILES_="$FILES_"$'\n'"$line";;
esac
done <<< "$1"
echo -e "$FILES_" | sed '/^\s*$/d'
}
function float {
bspc rule -a $1 -o state=floating
}
QUERY=$(echo "" | dmenu -p "search") || exit
DIRS=$(find ~/ -maxdepth 2 -type d -not -path '*/\.*' -iname "*$QUERY*")
# FILES=$(process_files "$(ag -i -g "$QUERY" --depth 3 $SOURCES)")
FILES=$(process_files "$(rg -S --files -g "*$QUERY*" $SOURCES)")
if [ "$DIRS" ]; then
CHOICES="$DIRS"$'\n'"$FILES"
else
CHOICES="$FILES"
fi
# get choice, and continue prompting while choice is a directory
CHOICE=$(echo -e "$CHOICES" | dmenu -is $IMG_DIM -l 10 -p "results") || exit
while [ -d "$CHOICE" ]; do
CHOICES=$(process_files "$(ls -r "$CHOICE")" $CHOICE/)
NEXT=$(echo -e "$CHOICES" | dmenu -is $IMG_DIM -l 10 -p "directory") || exit
CHOICE=$CHOICE/$NEXT
done
case "$CHOICE" in
*.png|*.jpg|*.jpeg|*.gif)
ACTION=$(echo -e "view\npath\ndata\nrm" | dmenu -p ">");;
*)
ACTION=$(echo -e "view\npath\nrm" | dmenu -p ">");;
esac
case "$ACTION" in
"view")
case "$CHOICE" in
*.png|*.jpg|*.jpeg) feh --scale-down "$CHOICE";;
*.mkv|*.mp4|*.webm) float mpv && mpv --autofit=50%x50% "$CHOICE";;
*.gif) gifview -a "$CHOICE";;
*.pdf) float zathura && zathura "$CHOICE";;
*.md) float URxvt && urxvt -e vi "$CHOICE";;
*) notify-send "unrecognized extension";;
esac;;
# remove with confirmation
"rm")
CONFIRM=$(dmenu -p "confirm? (y/n)")
if [ $CONFIRM = 'y' ]; then
# don't actually delete, move to /tmp
# so deletes on reboot
mv "$CHOICE" /tmp/
notify-send "deleted"
else
notify-send "canceled"
fi;;
# copy image data to clipboard
"data") imgclip "$CHOICE";;
# copy path to clipboard
"path") echo -n "${CHOICE} " | xsel -b;;
*) ;;
esac