#!/bin/bash

# Get the relative path of the Git repository (fallback to absolute path if needed)
repo_path=$(git rev-parse --show-toplevel)
repo_path=$(realpath --relative-to="$PWD" "$repo_path" 2>/dev/null || echo "$repo_path")

# Use provided editor or 'echo' as default
editor="${@:-echo}"

files=()

# Collect modified and untracked file paths
while IFS= read -r file; do
  files+=("$file")
done < <(git diff -w --name-only; git ls-files --others --exclude-standard)

# Prepend repository path and trim whitespace
for i in "${!files[@]}"; do
  files[$i]=$(echo "$repo_path/${files[$i]}" | xargs)
done

# Open files with editor (if any)
if (( ${#files[@]} )); then
  "$editor" "${files[@]}"
fi

