-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_git.bash
87 lines (70 loc) · 1.82 KB
/
setup_git.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# see https://scrapbox.io/takker/setup_git.sh
set -eu
catch () {
echo "Some error have occurred. Terminate the installation."
}
trap catch ERR
GITHUB_NAME="takker99"
GITHUB_EMAIL="37929109+takker99@users.noreply.github.com"
SSH_GITHUB_NAME="id_github_$GITHUB_NAME"
SSH_GITHUB_PATH="$HOME/.ssh/$SSH_GITHUB_NAME"
SSH_CONFIG_PATH="$HOME/.ssh/config"
if ! [ -e "${SSH_GITHUB_PATH}" ] || ! [ -e "${SSH_GITHUB_PATH}.pub" ]; then
echo "SSH keys for GitHub aren't found. Creating SSH keys..."
# 秘密鍵の中身を取り出す
copyKey() {
KEY=$(cat "${SSH_GITHUB_PATH}.pub")
if type "clip.exe" > /dev/null 2>&1; then
echo $KEY | clip.exe
else
echo $KEY | xsel
fi
}
mkdir -p ~/.ssh
ssh-keygen -t ed25519 -C $GITHUB_EMAIL -f $SSH_GITHUB_PATH -P "" -N ""
copyKey
echo "Copied the SSH public key to your clipboard. Please register it at https://github.com/settings/ssh/new"
select i in Registered CopyAgain
do
case $i in
Registered) break ;;
CopyAgain) echo "Copied again. Please register it" ; copyKey ;;
*) echo "$REPLY is an invalid value. Either \"1\" or \"2\" can be selected." ;;
esac
done
fi
if ! [ -e $SSH_CONFIG_PATH ]; then
cat << EOS >> $SSH_CONFIG_PATH
Host github github.com
User git
IdentityFile $SSH_GITHUB_PATH
HostName github.com
EOS
ssh github || :
fi
if ! [ -d ~/git/dotfiles ]; then
echo "Downloading takker99/dotfiles..."
mkdir -p ~/git
pushd ~/git
git clone git@github.com:takker99/dotfiles.git
popd
fi
if [ -e ~/.gitconfig ]; then
mv ~/.gitconfig ~/.gitconfig_old
fi
cat << EOS > ~/.gitconfig
[user]
email = $GITHUB_EMAIL
name = $GITHUB_NAME
[gui]
encoding = utf-8
[core]
editor = nvim
filemode = false
quotepath = false
[grep]
lineNumber = true
[alias]
[commit]
template = ~/git/dotfiles/.commit_template
EOS