git-issue-mvp, new_filename.sh| MacOS-compatible master
1. [[ ]]; -> [ ]; 2. Platform-agnostic timestamp generation - Added fallback logic for date +%s: First tries gdate (GNU date on macOS via Homebrew) Falls back to standard date +%s (works on Linux and modern macOS) Final fallback to perl for maximum compatibility 3. Replaced $(< "$id_file") with $(cat "$id_file") - The $(< file) syntax is bash-specific. Using cat is the portable alternative that works in all POSIX shells. 4. Changed == to = - In [ ... ] tests, the single = is the POSIX standard for string comparison. While == works in bash, = is more portable. 5. especially next_seq - Removed bash-specific features: - Removed shopt -s nullglob (bash-specific) - Removed [[ $f =~ ... ]] regex matching (bash-specific) - Removed BASH_REMATCH array (bash-specific) - Used find instead of globbing - More portable and handles edge cases better across platforms. - Parameter expansion for string extraction - Used ${filename#prefix} and ${temp%suffix} for portable string manipulation. - Portable number validation - Used case statement with pattern matching instead of regex. - Temporary file for max value - Since the while loop with find runs in a subshell (due to the pipe), we use a temporary file to persist the max value across iterations. - Added -print0 and -d '' - For safe handling of filenames with spaces or special characters. - 6. esp. gen_repo_id - Added check for /dev/urandom existence with [ -c /dev/urandom ] for better portability - Added fallback to openssl if /dev/urandom is not available Added final fallback using date, $$ (process ID), and either md5sum (Linux) or md5 (macOS) - More robust error handling - LC_ALL=C prefix - Forces tr to treat input as single-byte characters, preventing UTF-8 interpretation errors on macOS. - Error suppression and validation - Each method: - Redirects stderr to /dev/null with 2>/dev/null - Validates the result is non-empty and has the correct length Falls through to the next method if it fails - Removed bash-specific features: - Removed shopt -s nullglob - Removed [[ $f =~ ... ]] regex matching - Removed BASH_REMATCH array - Used find instead of glob patterns - Added macOS-specific method - jot is a BSD/macOS utility for generating sequences. - Improved hash fallback - Handles both md5 (macOS) and md5sum (Linux) with proper validation. - Guaranteed output - The absolute fallback at the end ensures the function always returns something, even if not ideal. - Better error handling - Each pipeline has || result="" to catch failures gracefully. 7. esp. repo_id_in_use - Replaced grep -q . with [ -n "$(find ...)" ] for simpler, more portable check - Added quotes around ${rid}-*.md for safety - Added 2>/dev/null to suppress errors if directory doesn't exist 8. parse_issue_id - Replaced [[ "$id" == *-* ]] - Changed to echo "$id" | grep -q '-' which works on all platforms. - Replaced regex =~ and BASH_REMATCH - Added validation using case statements - Validates that id_left contains only letters and id_right contains only digits using portable pattern matching. - Replaced sed ... <<< "$var" - Changed from bash-specific here-string to portable pipe: - Added edge case handling - If id_right is all zeros (e.g., "0000"), after removing leading zeros it becomes empty, so we set it to "0".