#!/usr/bin/env bash set -euo pipefail out="./quicklook" size=1024 recursive=0 force=0 inputs=() while [[ $# -gt 0 ]]; do case "$1" in --out) out="${2:?нужен путь}" shift 2 ;; --size) size="${2:?нужно число}" shift 2 ;; --recursive) recursive=1 shift ;; --force) force=1 shift ;; -h|--help) echo "Использование: quicklook_thumbnails.sh PATH... [--out DIR] [--size PX] [--recursive] [--force]" exit 0 ;; -*) echo "Неизвестный аргумент: $1" >&2 exit 2 ;; *) inputs+=("$1") shift ;; esac done if [[ ${#inputs[@]} -eq 0 ]]; then echo "Укажите хотя бы один файл или папку." >&2 exit 2 fi if [[ ! "$size" =~ ^[0-9]+$ ]] || [[ "$size" -lt 64 ]] || [[ "$size" -gt 4096 ]]; then echo "Размер должен быть от 64 до 4096 пикселей." >&2 exit 2 fi if ! command -v qlmanage >/dev/null 2>&1; then echo "qlmanage не найден." >&2 exit 1 fi mkdir -p "$out" out=$(cd "$out" && pwd) created=0 skipped=0 failed=0 for input in "${inputs[@]}"; do if [[ "$input" == "~"* ]]; then input="$HOME/${input#\~}" fi if [[ ! -e "$input" ]]; then echo "Пропуск, не найдено: $input" >&2 failed=$((failed + 1)) continue fi if [[ -d "$input" ]]; then if [[ "$recursive" -eq 1 ]]; then list=$(find "$input" -type f -not -path "$out/*" -print) else list=$(find "$input" -maxdepth 1 -type f -not -path "$out/*" -print) fi else list="$input" fi while IFS= read -r file; do [[ -z "$file" ]] && continue name=$(basename "$file") if [[ -e "$out/$name.png" && "$force" -eq 0 ]]; then echo " уже есть: $out/$name.png" skipped=$((skipped + 1)) continue fi qlmanage -t -s "$size" -o "$out" "$file" >/dev/null 2>&1 || true if [[ -f "$out/$name.png" ]]; then printf ' %s\n' "$out/$name.png" created=$((created + 1)) else echo " нет превью: $file" >&2 failed=$((failed + 1)) fi done <<< "$list" done echo echo "Создано превью: $created. Уже было: $skipped. Не удалось: $failed."