Skip to content

Instantly share code, notes, and snippets.

@dewomser
Last active April 21, 2025 10:57
Show Gist options
  • Save dewomser/743328e2b14a067f15c84b832e1ed579 to your computer and use it in GitHub Desktop.
Save dewomser/743328e2b14a067f15c84b832e1ed579 to your computer and use it in GitHub Desktop.
Toot the local git diff in a specific git repository
#!/bin/bash
#This script is useing "toot" ang "gist". Must be installed
# Variables
REPO_NAME="Hello_world"
REPO_REMOTE_ROOT="https://github.com/foo"
REPO_DIR="/home/fpp/git/$REPO_NAME"
GIST_DESCRIPTION="Latest commit diff $REPO_NAME"
GIST_FILENAME="diff.txt"
MASTODON_MESSAGE="Check out the latest commit diff: $REPO_NAME"
# Change to the repository directory
cd "$REPO_DIR" || exit
# Get the first 10 lines of the diff from the latest commit
DIFF=$(git diff HEAD~1 HEAD | head -n 10)
# Create a temporary file for the diff
TEMP_FILE=$(mktemp)
echo "$REPO_NAME" > "$TEMP_FILE"
echo "$REPO_REMOTE_ROOT/$REPO_NAME" >> "$TEMP_FILE"
echo "------------" >> "$TEMP_FILE"
echo "$DIFF" >> "$TEMP_FILE"
# Create a GitHub Gist
GIST_URL=$(gist -d "$GIST_DESCRIPTION" "$TEMP_FILE")
# Send a message to Mastodon
toot post "$MASTODON_MESSAGE $GIST_URL"
# Clean up the temporary file
rm "$TEMP_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment