forked from lewagon/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·75 lines (66 loc) · 2.14 KB
/
install.sh
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
#!/bin/zsh
# Define a function which rename a `target` file to `target.backup` if the file
# exists and if it's a 'real' file, ie not a symlink
backup() {
target=$1
if [ -e "$target" ]; then
if [ ! -L "$target" ]; then
mv "$target" "$target.backup"
echo "-----> Moved your old $target config file to $target.backup"
fi
fi
}
symlink() {
file=$1
link=$2
if [ ! -e "$link" ]; then
echo "-----> Symlinking your new $link"
ln -s $file $link
fi
}
# For all files `$name` in the present folder except `*.sh`, `README.md`, `settings.json`,
# and `config`, backup the target file located at `~/.$name` and symlink `$name` to `~/.$name`
for name in aliases gitconfig irbrc rspec zprofile zshrc; do
if [ ! -d "$name" ]; then
target="$HOME/.$name"
backup $target
symlink $PWD/$name $target
fi
done
# Install zsh-syntax-highlighting plugin
CURRENT_DIR=`pwd`
ZSH_PLUGINS_DIR="$HOME/.oh-my-zsh/custom/plugins"
mkdir -p "$ZSH_PLUGINS_DIR" && cd "$ZSH_PLUGINS_DIR"
if [ ! -d "$ZSH_PLUGINS_DIR/zsh-syntax-highlighting" ]; then
echo "-----> Installing zsh plugin 'zsh-syntax-highlighting'..."
git clone https://github.com/zsh-users/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting
fi
cd "$CURRENT_DIR"
# Symlink VS Code settings and keybindings to the present `settings.json` and `keybindings.json` files
# If it's a macOS
if [[ `uname` =~ "Darwin" ]]; then
CODE_PATH=~/Library/Application\ Support/Code/User
# Else, it's a Linux
else
CODE_PATH=~/.config/Code/User
# If this folder doesn't exist, it's a WSL
if [ ! -e $CODE_PATH ]; then
CODE_PATH=~/.vscode-server/data/Machine
fi
fi
for name in settings.json keybindings.json; do
target="$CODE_PATH/$name"
backup $target
symlink $PWD/$name $target
done
# Symlink SSH config file to the present `config` file for macOS and add SSH passphrase to the keychain
if [[ `uname` =~ "Darwin" ]]; then
target=~/.ssh/config
backup $target
symlink $PWD/config $target
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
fi
# Refresh the current terminal with the newly installed configuration
exec zsh
echo "👌 Carry on with git setup!"