-
-
Save ryancdotorg/79d0dae29fb475a6e39612d08648ab9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
exec /usr/bin/git "$@" | |
# Find the real git binary | |
GIT_BIN=/bin/false | |
SAVED_IFS="$IFS" | |
IFS=: | |
for d in $PATH | |
do | |
d="$d/git" | |
if [ "$d" != "$0" -a -e "$d" ]; then | |
GIT_BIN="$d" | |
break | |
fi | |
done | |
IFS="$SAVED_IFS" | |
# Hack to make defaultBranch work in old versions of git | |
if [ $# -eq 1 -a "$1" = "init" ]; then | |
$GIT_BIN init && \ | |
$GIT_BIN checkout -b "`$GIT_BIN config init.defaultBranch || echo main`" | |
exit $? | |
fi | |
function timestamp() { | |
TZ="$(printf 'FAKE%+03d:%02d' $(($RANDOM%49-24)) $(($RANDOM%60)))" \ | |
date +%Y-%m-%dT%H:%M:%S%z | |
} | |
# Randomize the timezone | |
# GIT_AUTHOR_DATE=\"$(date +%Y-%m-%dT%H:%M:%S%z)\"; | |
# GIT_COMMITTER_DATE=\"$(date +%Y-%m-%dT%H:%M:%S%z)\"; | |
if [ ${GIT_RANDOMIZE_TZ:=1} -ne 0 ]; then | |
export TZ=`printf 'FAKE%+03d:%02d' $(($RANDOM%49-24)) $(($RANDOM%60))` | |
fi | |
# Detect whether to use dotfile mode | |
# Loosely based on https://www.ackama.com/what-we-think/the-best-way-to-store-your-dotfiles-a-bare-git-repository-explained/ | |
# Tl;dr setup: git init --bare $HOME/.dotfiles | |
GIT_DIR="`$GIT_BIN rev-parse --show-toplevel 2>/dev/null||true`" | |
if [ -z "$GIT_DIR" -a -d "${GIT_DOTFILES=$HOME/.dotfiles}" ]; then | |
# Check if we're in the home dir or a hidden child of it | |
if [ "$PWD" = "$HOME" ] || [ "$PWD" = "$HOME/bin" ] || [[ "${PWD#$HOME/}" =~ ^[.] ]] && [[ ! "${PWD#$HOME/}" =~ ^[.]vim/pack ]]; then | |
# Untracked files would be very noisy, default them to hidden | |
"$GIT_BIN" --git-dir="$GIT_DOTFILES" --work-tree="$HOME" \ | |
config --local status.showUntrackedFiles >/dev/null || \ | |
"$GIT_BIN" --git-dir="$GIT_DOTFILES" --work-tree="$HOME" \ | |
config --local status.showUntrackedFiles no | |
# Execute wrapped command | |
exec "$GIT_BIN" --git-dir="$GIT_DOTFILES" --work-tree="$HOME" \ | |
"$@" | |
fi | |
fi | |
# Execute wrapped command | |
exec "$GIT_BIN" "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment