diff --git a/README.md b/README.md index 548529c..580b495 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/index.sh b/index.sh index d4d7ca8..6b6c099 100755 --- a/index.sh +++ b/index.sh @@ -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 @@ -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 ..