-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
executable file
·192 lines (154 loc) · 7.59 KB
/
install
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env bash
COLOR_RED='\033[0;31m'
COLOR_YELLOW='\033[0;33m'
COLOR_GREEN='\033[0;32m'
COLOR_BLUE='\033[0;34m'
COLOR_RESET='\033[0m'
SCRIPT_DIR=$(dirname $(readlink -f $0))
checks() {
# CHECKS #
if [[ ! -x "$(command -v nvim)" ]]; then
echo -e "${COLOR_RED}Neovim is not installed! Please install neovim and try again.${COLOR_RESET}"
exit 1
fi
NVIM_VERSION=$(nvim --version | grep -oP '(?<=^NVIM v).+' | tr -d '"')
NVIM_MINOR_VERSION=$(echo $NVIM_VERSION | cut -d '.' -f 2)
if [[ $NVIM_MINOR_VERSION -lt 9 ]]; then
echo -e "${COLOR_RED}Neovim version is too old! Please update neovim and try again.${COLOR_RESET}"
echo -e "${COLOR_YELLOW}You will need at least version 0.9.0${COLOR_RESET}"
exit 1
fi
# DEPENDENCIES #
# This script will install the dependencies for the dotfiles we assume that
# you already have neovim
DISTRO=$(cat /etc/os-release | grep -oP '(?<=^ID=).+' | tr -d '"')
case "$DISTRO" in
"arch")
echo -e "${COLOR_BLUE}Installing dependencies for Arch Linux...${COLOR_RESET}"
sudo pacman -S --needed --noconfirm ripgrep fd fzf tmux
;;
"manjaro")
echo -e "${COLOR_BLUE}Installing dependencies for Manjaro...${COLOR_RESET}"
sudo pacman -S --needed --noconfirm ripgrep fd fzf tmux
;;
"endeavouros")
echo -e "${COLOR_BLUE}Installing dependencies for EndeavourOS...${COLOR_RESET}"
sudo pacman -S --needed --noconfirm ripgrep fd fzf tmux
;;
"ubuntu")
echo -e "${COLOR_BLUE}Installing dependencies for Ubuntu...${COLOR_RESET}"
sudo apt install -y ripgrep fd-find fzf tmux
;;
"linuxmint")
echo -e "${COLOR_BLUE}Installing dependencies for Linux Mint...${COLOR_RESET}"
sudo apt install -y ripgrep fd-find fzf tmux
;;
*)
echo -e "${COLOR_RED}Unsupported distro: $DISTRO${COLOR_RESET}"
echo -e "You can install the dependencies manually: "
echo -e " - ripgrep <https://github.com/BurntSushi/ripgrep>"
echo -e " - fd <https://github.com/sharkdp/fd>"
echo -e " - fzf <https://github.com/junegunn/fzf>"
echo -e " - tmux <https://github.com/tmux/tmux>"
echo -e "${COLOR_YELLOW}You can raise an issue at https://github.com/alexjercan/nvim.dotfiles/issues to add support for your distro${COLOR_RESET}"
read -n1 -rep "Install the dependencies manually and then continue (y) or quit (n)" INSTALL_MANUALLY
if [[ ! $INSTALL_MANUALLY =~ ^[Yy]$ ]]; then
exit 1
fi
esac
}
neovim_setup() {
# NEOVIM SETUP #
echo -e "${COLOR_BLUE}Installing neovim config...${COLOR_RESET}"
NVIM_DIR=$SCRIPT_DIR/nvim
## BACKUP OLD CONFIG ##
# This will create a backup of the old nvim config just in case you want to revert back to it
# It will copy the old config to the nvim.bak directory
# Then we remove the old nvim config
echo -e "Creating old config backup at ~/.config/nvim.bak"
unlink ~/.config/nvim.bak 2> /dev/null || rm -rf ~/.config/nvim.bak
mkdir -p ~/.config/nvim.bak
cp -r ~/.config/nvim/* ~/.config/nvim.bak
unlink ~/.config/nvim 2> /dev/null || rm -rf ~/.config/nvim # remove old nvim config
## DEFAULT PLUGINS ##
# Changed this to all plugins by default, you have to manually delete the ones you don't want
echo "Installing plugins..."
echo "You can remove the plugins you don't want from the ~/.config/nvim/lua/plugins directory"
## INSTALL CONFIG ##
# This will create the symbolic link to the nvim config directory
ln -s $NVIM_DIR ~/.config/nvim
}
tmux_setup() {
# TMUX SETUP #
echo -e "${COLOR_BLUE}Installing tmux config...${COLOR_RESET}"
TMUX_DIR=$SCRIPT_DIR/tmux
unlink ~/.tmux.conf 2> /dev/null || rm -f ~/.tmux.conf # remove old tmux config
ln -s $TMUX_DIR/.tmux.conf ~/.tmux.conf
# This will install the tmux plugin manager and the plugins
if [[ ! -d ~/.tmux/plugins/tpm ]]; then
echo "Installing tmux plugin manager..."
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
~/.tmux/plugins/tpm/bin/install_plugins
}
scripts_setup() {
# SCRIPTS SETUP #
echo -e "${COLOR_BLUE}Installing dev scripts...${COLOR_RESET}"
SCRIPTS_DIR=$SCRIPT_DIR/scripts
mkdir -p ~/.local/bin
## TMUX-SESSIONIZER ##
read -n1 -rep "Would you like to install tmux-sessionizer? (y,n)" INSTALL_TMUX_SESSIONIZER
if [[ $INSTALL_TMUX_SESSIONIZER =~ ^[Yy]$ ]]; then
read -rep "Enter the path to the directories that you want to use for tmux-sessionizer (separated by a space): " SESSIONIZER_DIRS
unlink ~/.local/bin/tmux-sessionizer 2> /dev/null || rm -rf ~/.local/bin/tmux-sessionizer
TMUX_SESSIONIZER_PATH=$SCRIPTS_DIR/tmux-sessionizer
echo "#!/usr/bin/env bash" > ~/.local/bin/tmux-sessionizer
echo "" >> ~/.local/bin/tmux-sessionizer
echo "if [ "\$#" -eq 0 ]; then" >> ~/.local/bin/tmux-sessionizer
echo " $TMUX_SESSIONIZER_PATH $SESSIONIZER_DIRS" >> ~/.local/bin/tmux-sessionizer
echo "elif [[ "\$#" -eq 2 && \$1 == \"--open\" || \$1 == \"-o\" ]]; then" >> ~/.local/bin/tmux-sessionizer
echo " $TMUX_SESSIONIZER_PATH --open \$2" >> ~/.local/bin/tmux-sessionizer
echo "elif [[ "\$#" -eq 2 && \$1 == \"--create\" || \$1 == \"-c\" ]]; then" >> ~/.local/bin/tmux-sessionizer
echo " names=($SESSIONIZER_DIRS)" >> ~/.local/bin/tmux-sessionizer
echo " selected=()" >> ~/.local/bin/tmux-sessionizer
echo " PS3=\"Choose the project directory: \"" >> ~/.local/bin/tmux-sessionizer
echo " select name in \"\${names[@]}\" ; do" >> ~/.local/bin/tmux-sessionizer
echo " for reply in \$REPLY ; do" >> ~/.local/bin/tmux-sessionizer
echo " selected+=(\${names[reply - 1]})" >> ~/.local/bin/tmux-sessionizer
echo " done" >> ~/.local/bin/tmux-sessionizer
echo " [[ \$selected ]] && break" >> ~/.local/bin/tmux-sessionizer
echo " done" >> ~/.local/bin/tmux-sessionizer
echo " $TMUX_SESSIONIZER_PATH --create \$selected/\$2" >> ~/.local/bin/tmux-sessionizer
echo "fi" >> ~/.local/bin/tmux-sessionizer
chmod +x ~/.local/bin/tmux-sessionizer
fi
}
post_install() {
# Check if you have a patched font installed
echo -en "Can you see a checkmark? (y/n) \u2713"
read -n1 -rs CHECKMARK_ANSWER
echo ""
echo -en "Can you see a branch symbol? (y/n) \uE0A0"
read -n1 -rs BRANCH_ANSWER
echo ""
if [[ ! $CHECKMARK_ANSWER =~ ^[Yy]$ || ! $BRANCH_ANSWER =~ ^[Yy]$ ]]; then
echo -e "${COLOR_YELLOW}You need to install a patched font in order to see the dev icons otherwise some things will look weird${COLOR_RESET}"
echo -e "You can find a list of patched fonts at https://www.nerdfonts.com/font-downloads"
fi
echo -e "${COLOR_GREEN}Installation complete!${COLOR_RESET}"
echo -e "${COLOR_YELLOW}You need to add ~/.local/bin to your PATH variable in order to use the dev scripts${COLOR_RESET}"
}
checks
read -n1 -rep 'Do you want to install the neovim config (this will overwrite your current config)? [y/n]: ' answer
if [[ $answer =~ ^[Yy]$ ]]; then
neovim_setup
fi
read -n1 -rep 'Do you want to install the tmux config (this will overwrite your current config)? [y/n]: ' answer
if [[ $answer =~ ^[Yy]$ ]]; then
tmux_setup
fi
read -n1 -rep 'Do you want to install the dev scripts? [y/n]: ' answer
if [[ $answer =~ ^[Yy]$ ]]; then
scripts_setup
fi
post_install