Created
June 1, 2025 16:37
-
-
Save wITTus/a008dffe209646bd2b3841799cb0ecbd to your computer and use it in GitHub Desktop.
Semi-automatic BASH File Organizer Script
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
organize_files() { | |
local maxdepth=1 | |
local model="qwen3" | |
#local model="qwen3:30b-a3b" | |
#local model="qwen3:14b" | |
local OPTIND opt | |
print_help() { | |
cat <<EOF | |
Usage: organize_files [-d N|--depth=N] [-m NAME|--model=NAME] [-h|--help] | |
Options: | |
-d, --depth N Set max depth for file search (default: 1) | |
-m, --model NAME Set the model to use for ollama (default: qwen3) | |
-h, --help Show this help message and exit | |
EOF | |
} | |
while getopts ":d:m:h-:" opt; do | |
case "$opt" in | |
d) maxdepth="$OPTARG" ;; | |
m) model="$OPTARG" ;; | |
h) print_help; return 0 ;; | |
-) | |
case "${OPTARG}" in | |
depth=*) maxdepth="${OPTARG#*=}" ;; | |
depth) | |
maxdepth="${!OPTIND}"; OPTIND=$((OPTIND + 1)) | |
;; | |
model=*) model="${OPTARG#*=}" ;; | |
model) | |
model="${!OPTIND}"; OPTIND=$((OPTIND + 1)) | |
;; | |
help) print_help; return 0 ;; | |
*) echo "Unknown option --${OPTARG}" >&2; return 1 ;; | |
esac | |
;; | |
\?) echo "Invalid option: -$OPTARG" >&2; return 1 ;; | |
:) echo "Option -$OPTARG requires an argument." >&2; return 1 ;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
local output prompt | |
output=$(find . -maxdepth "$maxdepth" -type f ! -name ".*" | sed 's/^/ /' | cat -n) | |
prompt=$(cat <<EOF | |
Act as a smart file organizer. Your task is to analyze the file list and group files based on shared meaning, function, or file type. Prioritize semantic groupings (e.g., "invoices", "scripts", "images") over simple extension-based sorting if clear patterns exist. | |
Your response must contain: | |
1. A tree view showing the proposed folder layout. | |
2. A shell script (using mkdir and mv, safe quoting) that executes the reorganization. | |
Do not include explanations, comments, or formatting beyond what is requested. Your context length is limited, so don't repeat the file list over and over again. | |
Here are the files: | |
$(echo "$output") | |
EOF | |
) | |
ollama run "$model" "$prompt" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment