31 lines
792 B
Bash
Executable file
31 lines
792 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# Interactive git patch applier - finds git repos and applies patch from stdin
|
|
|
|
# Save stdin (the patch) to a temp file
|
|
patch_file=$(mktemp /tmp/patch.XXXXXX)
|
|
cat >"$patch_file"
|
|
|
|
# Find git repos and select with fzf
|
|
repo=$(find ~/projects ~/code ~/dotfiles ~ -maxdepth 3 -type d -name ".git" 2>/dev/null |
|
|
sed 's/\/.git$//' |
|
|
sort -u |
|
|
fzf --prompt="Select repo to apply patch: " --height=40% --reverse)
|
|
|
|
if [ -z "$repo" ]; then
|
|
echo "No repo selected, patch saved to: $patch_file"
|
|
exit 1
|
|
fi
|
|
|
|
cd "$repo" || exit 1
|
|
echo "Applying patch to: $repo"
|
|
git apply "$patch_file"
|
|
status=$?
|
|
|
|
if [ $status -eq 0 ]; then
|
|
echo "Patch applied successfully!"
|
|
rm "$patch_file"
|
|
else
|
|
echo "Failed to apply patch. Patch saved to: $patch_file"
|
|
fi
|
|
|
|
exit $status
|