This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Single-file Bash CLI tool (prepare-car-usb.sh) that prepares USB music libraries for car stereos. Cleans filenames, removes junk files, shortens names, adds numeric prefixes, and optionally organizes files into artist folders.
Must remain compatible with Bash >= 3.2 (macOS) and work on both GNU and BSD utilities.
./prepare-car-usb.sh --dry-run /path/to/usb # preview
./prepare-car-usb.sh /path/to/usb # apply
./prepare-car-usb.sh --album-folders /path/to/usb # organize into artist dirs
./prepare-car-usb.sh --max-length 40 --no-prefix --extensions mp3,flac /path/to/usbshellcheck prepare-car-usb.sh- No
${var,,}(Bash 4+) — usetr '[:upper:]' '[:lower:]'viato_lower() - No
sort -z(BSD incompatible) — use shell glob for sorted directory listings - No
paste— usetr '\n' ','withsed 's/,$//' - No GNU-specific sed (
\+,-r) — usesed -Efor ERE, which works on both GNU and BSD - No
rename,perl,python,jq— only standard coreutils - Use
n=$((n + 1))instead of((n++))to avoidset -eedge cases
The script runs a configurable pipeline in main():
- remove_junk_files — deletes dotfiles,
Thumbs.db,desktop.ini - organize_album_folders — (optional,
--album-folders) groups flat "Artist - Title" files into artist directories; skips purely numeric prefixes like "01 - Song" - clean_and_shorten_filenames — lowercases, strips special chars, truncates to
--max-length - add_numeric_prefixes — (optional, default on) adds
001_style prefixes per directory - sync_changes — flushes to disk
Step numbering is dynamic — TOTAL_STEPS and CURRENT_STEP adapt to enabled features.
Key patterns:
DRY_RUNglobal flag gates all destructive operations (rm,mv,mkdir)safe_move()handles collisions gracefully (warns + skips, never overwrites)find_unique_path()appends_Nsuffixes to avoid collisionsis_audio_file()checks against the configurableEXTENSIONSlistclean_name()pipeline: lowercase → expand&→ strip special chars → underscores → truncateto_lower()wrapstrfor portable case conversion (replaces Bash 4+${var,,})- Uses
find ... -print0withread -d ''for safe filename handling - Uses shell globs (not
sort -z) for sorted per-directory file iteration - Color output auto-detected (TTY check), disabled with
--no-color - Counters track junk/renamed/prefixed/grouped/skipped for summary output