Skip to content

Improvement to diffsense.sh #43

@eonist

Description

@eonist

The script is well-structured overall, but here are several improvements you could make:

Error Handling & Robustness

Set strict error handling at the top: Add set -euo pipefail to fail fast on errors and undefined variables.

Quote variable expansions consistently: Several places miss quotes, which could cause issues with spaces in paths (e.g., "$raw_arg" in the parse loop).

Validate required commands exist: Check for git, shortcuts, sw_vers availability before using them.

Code Quality Issues

Fix the typo in error message: Line 294 says "Diffsensee" instead of "Diffsense".

Improve the macOS version check: The requirement for "macOS 26" seems unusually high (macOS Sequoia is version 15). This appears to be an error - consider using a realistic minimum version.

Simplify the status mapping in build_file_summary: The renamed file handling (R*) could break if there are tabs in the path. Consider using --name-status -z with null-terminated output for safer parsing.

Performance Optimizations

  • Cache build_diff_excludes output: It's called twice (in build_file_summary and prepare_diff). Generate once and reuse.
  • Use array directly in git commands: Instead of building exclude args in a loop, you could use printf -- ':(exclude)%s\n' "${NOISE_PATTERNS[@]}".

UX Improvements

Provide better feedback during processing: Add a spinner or message like "🤖 Generating commit message..." since the LLM call may take time.

Validate commit message quality: Check if the generated message meets basic git conventions (e.g., not empty, reasonable length) before attempting commit.

Support --help anywhere in args: Currently only works as first argument.

Security Considerations

Sanitize input to shortcuts command: The payload is passed via stdin, but consider what happens if the diff contains special characters that could affect processing.

Add option to preview before commit: A --dry-run flag would let users see the generated message without committing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions