Skip to content

Instantly share code, notes, and snippets.

@wbv
Last active November 6, 2022 06:30
git fortune
#!/bin/sh
# get your `fortune` from a random commit in the current git repository
# falling back to a helpful message
in_git_repo=$?
if ! git rev-parse --is-inside-work-tree >/dev/null 2>/dev/null; then
cat <<-EOF
I'm not being run from inside a git repository.
-- git-fortune.sh
EOF
exit 1
fi
git rev-list --all \
| cut -f1 -d' ' \
| sort -R \
| head -n 1 \
| git rev-list \
--no-walk \
--no-commit-header \
--stdin \
--format="format:%s%b%n%n -- %an"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment