Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@ Make your GitHub history back to 1990.

## Travel Back

[Create a new repo](https://github.com/new) named `1990` on GitHub.

[Generate a personal access token](https://github.com/settings/tokens/new) on GitHub and copy it.

Run the following script
Run the following script and follow the prompts.

```bash
$ sh -c "$(curl -fsSL https://raw.github.com/antfu/1990-script/master/index.sh)"
```

[Create a new repo](https://github.com/new) named `1990` on GitHub.

If you use SSH, just paste the new repo's SSH URL and you're done :)

Otherwise, [Generate a personal access token](https://github.com/settings/tokens/new) on GitHub and copy it.

Enter you GitHub username and access token and then you are done :)

## Explanations

This project works on the way `git` records commit. Whenever you commit something, `git` puts an `Unix Timestamp` on it to record when you committed it. An [`Unix Timestamp`](https://www.unixtimestamp.com/) is the way computers store the current time. An `Unix timestamp` is a `32-bit` number which stores the number of seconds that has passed from January 1st, 1970 at UTC, the `Unix Epoch`.

The script firstly creates a directory with the name of the wanted year - `line 9` `mkdir $YEAR`
The script firstly creates a directory with the name of the wanted year - `line 42` `mkdir $YEAR`

The script then initializes the directory as a git repository, using `git init` - `line 12` `git init`
The script then initializes the directory as a git repository, using `git init` - `line 45` `git init`

The script then stages all the files `git add .` and commits it, using the date `{YEAR}-01-01T18:00:00` (`line 16`) or `6pm, 1st January, 1990` (default of the `YEAR` variable)
The script then stages all the files `git add .` and commits it, using the date `{YEAR}-01-01T18:00:00` (`line 50`) or `6pm, 1st January, 1990` (default of the `YEAR` variable)

This is the `ISO Date-Time format` for storing time: `YYYY-MM-DDTHH:MM:SS`.

Expand Down
46 changes: 39 additions & 7 deletions index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,43 @@

_() {
YEAR="1990"
echo "GitHub Username: "
read -r USERNAME
echo "GitHub Access token: "
read -r ACCESS_TOKEN
tabs 3
echo
printf "\tStep 0: \e]8;;https://github.com/new\e\\Create a new repo named 1990. (Ctrl/CMD + Click)\e]8;;\e\\ \n"
echo
echo "\tStep 1: Pick your preferred git login method"
echo
PS3="Please enter 1 or 2: "
options=("HTTPS (GitHub Access Token)" "SSH")
select opt in "${options[@]}"
do
case $opt in
"HTTPS (GitHub Access Token)")
echo
printf "\tStep 2: \e]8;;https://github.com/settings/tokens/new\e\\Generate a personal access token (Ctrl/CMD + Click)\e]8;;\e\\ \n"
echo "Copy and paste it below: "
read -r ACCESS_TOKEN
[ -z "$ACCESS_TOKEN" ] && exit 1
echo
echo "\tStep 3: Please enter your GitHub username: "
read -r USERNAME
[ -z "$USERNAME" ] && exit 1
echo
break
;;
"SSH")
echo
echo "\tStep 2: Copy the SSH link to your repo and paste it below"
read -r REPO_LINK
[ -z "$REPO_LINK" ] && exit 1
USERNAME=${REPO_LINK%/*} # remove suffix after "/"
USERNAME=${USERNAME#*:} # remove prefix before ":"
break
;;
*) echo "invalid option $REPLY, please enter 1 or 2";;
esac
done

[ -z "$USERNAME" ] && exit 1
[ -z "$ACCESS_TOKEN" ] && exit 1
[ ! -d $YEAR ] && mkdir $YEAR

cd "${YEAR}" || exit
Expand All @@ -19,7 +49,9 @@ _() {
GIT_AUTHOR_DATE="${YEAR}-01-01T18:00:00" \
GIT_COMMITTER_DATE="${YEAR}-01-01T18:00:00" \
git commit -m "${YEAR}"
git remote add origin "https://${ACCESS_TOKEN}@github.com/${USERNAME}/${YEAR}.git"
[ -z "$REPO_LINK" ] && \
git remote add origin "https://${ACCESS_TOKEN}@github.com/${USERNAME}/${YEAR}.git" || \
git remote add origin "${REPO_LINK}"
git branch -M main
git push -u origin main -f
cd ..
Expand Down