Files
scripts-bash/document_finder.sh
2026-03-30 15:48:25 -06:00

52 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# Ruta a tu carpeta de documentos
DOC_DIR="$HOME/Documents"
CACHE="$DOC_DIR/Docs/rofi_documentos.txt"
# Mapeo de íconos Nerd Fonts por extensión
get_icon() {
case "${1##*.}" in
pdf) echo "" ;; # ícono de PDF (nf-mdi-file_pdf_box)
txt|md|log) echo "" ;; # ícono de texto
doc|docx) echo "" ;; # ícono de Word
xls|xlsx) echo "" ;; # Excel
ppt|pptx) echo "" ;; # PowerPoint
*) echo "" ;; # genérico
esac
}
# Si el caché no existe o tiene más de 60 segundos, actualízalo
if [[ ! -f "$CACHE" ]]; then
find "$DOC_DIR" -type f \( -iname '*.pdf' \) > "$CACHE"
fi
# Crear lista formateada con íconos
list=""
while IFS= read -r file; do
icon=$(get_icon "$file")
base=$(basename "$file")
list+="$icon $base ::$file\n"
done < "$CACHE"
# Mostrar menú con rofi
seleccion=$(echo -e "$list" | rofi -dmenu -markup-rows -p " Documentos")
# Extraer solo el nombre del archivo
archivo=$(echo "$seleccion" | cut -d' ' -f2-)
echo "SELECCION :>>>"$seleccion
echo "ARCHIVO :>>>"$archivo
# Abrir si se seleccionó algo
[[ -z "$archivo" ]] && exit
# Buscar la ruta completa del archivo
#ruta=$(find "$DOC_DIR" -type f -name "$archivo" | head -n 1)
ruta="${seleccion##*::}"
firefox -P default-release "$ruta" &