-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·146 lines (131 loc) · 4.34 KB
/
setup.sh
File metadata and controls
executable file
·146 lines (131 loc) · 4.34 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Setup error handling
set -e
trap 'echo "Error at $BASH_SOURCE on line $LINENO!"' ERR
ALWAYS_YES=
if [[ "$1" == "-y" ]]; then
ALWAYS_YES="y"
fi
maybe_read () {
if [[ ! -z "$ALWAYS_YES" ]]; then
echo "$1 y"
export REPLY="y"
else
read -p "$1" -r
echo
fi
}
# Prompt user about this script
echo
maybe_read "This script is only prepared to run on Ubuntu or Mac OSX. Do you want to continue? (y/n) "
if [[ ! "$REPLY" =~ ^[Yy](es)?$ ]]; then
echo "Feel free to edit this script file as desired to make it work on your OS/distro. If you rewrite it for your own operating system / distro and it works, do let me know so I can add your script to this repository. Thanks!"
echo
exit
fi
# Check for existant ~/.vim or ~/.vimrc
if [[ -d ~/.vim || -f ~/.vimrc || -d ~/.tmux || -f ~/.tmux.conf ]]; then
maybe_read "An existant ~/.vim, ~/.vimrc, ~/.tmux, or ~/.tmux.conf has been found. Overwrite all contents? (y/n) "
if [[ "$REPLY" =~ ^[Yy](es)?$ ]]; then
rm -rf ~/.vim
rm -f ~/.vimrc
rm -rf ~/.tmux
rm -f ~/.tmux.conf
else
echo "Cannot continue unless ~/.vim, ~/.vimrc, ~/.tmux, and ~/.tmux.conf no longer exist"
echo
exit 1
fi
fi
# Install dependencies
if [[ "$OSTYPE" =~ ^darwin ]]; then
brew install ccls node clang-format vim ripgrep fd tmux
else
# Install any Apt Pre-requisites
sudo apt-get update -y
pkgs='curl ccls clang-format vim-gtk3 ripgrep fd-find tmux'
if ! dpkg -s $pkgs >/dev/null 2>&1; then
sudo apt-get install $pkgs -y
fi
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
source ~/.nvm/nvm.sh
# Install NodeJS and NPM
nvm install 18.17.0
nvm use 18.17.0
fi
# Setup tmux plugins
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
cp tmux.conf ~/.tmux.conf
~/.tmux/plugins/tpm/bin/install_plugins
# Setup Vim Plugins
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
cp vimrc ~/.vimrc
# Install fzf via plugin instead of package manager, because apt's version is too old
echo "\n" | vim +PluginInstall +':call fzf#install()' +qall
# Copy coc-settings.json
cp coc-settings.json ~/.vim
# Checkout release version of coc
cd ~/.vim/bundle/coc.nvim
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --depth=1 origin release
git checkout release
# Find bashrc path based on OS
if [[ "$OSTYPE" =~ ^darwin ]]; then
BASH_RC="$HOME/.profile"
else
BASH_RC="$HOME/.bashrc"
fi
# Setup bashrc
if ! cat "$BASH_RC" | grep "Set vim as the default editor" > /dev/null; then
echo >> "$BASH_RC"
echo '# Set vim as the default editor' >> "$BASH_RC"
echo 'export VISUAL=vim' >> "$BASH_RC"
echo 'export EDITOR="$VISUAL"' >> "$BASH_RC"
echo >> "$BASH_RC"
fi
if [[ ! "$OSTYPE" =~ ^darwin ]]; then
# Prompt for caps lock to ctrl remap
echo
maybe_read "Do you want to remap CAPS LOCK to CTRL? (y/n) "
if [[ "$REPLY" =~ ^[Yy](es)?$ ]]; then
if ! which setxkbmap; then
echo "Note: Could not find command \"setxkbmap\", will not remap CAPS LOCK to CTRL."
else
echo Executing \"setxkbmap -option ctrl:nocaps ...\"
setxkbmap -option ctrl:nocaps
echo Adding \"setxkbmap -option ctrl:nocaps\" to ~/.profile ...
if ! cat ~/.profile | grep "Remap CAPS LOCK to CTRL" > /dev/null; then
echo >> ~/.profile
echo '# Remap CAPS LOCK to CTRL' >> ~/.profile
echo 'setxkbmap -option ctrl:nocaps' >> ~/.profile
echo >> ~/.profile
fi
fi
else
echo In the future, you can do this with \"setxkbmap -option ctrl:nocaps\"
echo This command can be added to your \"~/.profile\" to execute on login
fi
echo
echo Deactivating can be done by typing \"setxkbmap -option\"
echo Deactivating can be done permanently by editing \"~/.profile\"
echo
# Install vim into root user
# On Mac, the root user is /home/$USER
echo
ROOT_HOME=/root
if [[ "$HOME" -ef "$ROOT_HOME" ]]; then
echo "Installed this vimrc into root!"
else
maybe_read "Do you want to install this vimrc into the root user as well? (y/n) "
if [[ "$REPLY" =~ ^[Yy](es)?$ ]]; then
sudo rm -rf "$ROOT_HOME/.vim"
sudo rm -f "$ROOT_HOME/.vimrc"
sudo cp -r "$HOME/.vim" "$ROOT_HOME/.vim"
sudo cp "$HOME/.vimrc" "$ROOT_HOME/.vimrc"
fi
fi
fi
echo "Done!"
echo "Please restart your terminal or run 'exec bash' to update your PATH"
echo