forked from alexjercan/nvim.dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·191 lines (159 loc) · 7.27 KB
/
install
File metadata and controls
executable file
·191 lines (159 loc) · 7.27 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
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
#!/usr/bin/env bash
# ANSI color codes for terminal formatting
COLOR_RED='\033[0;31m'
COLOR_YELLOW='\033[0;33m'
COLOR_GREEN='\033[0;32m'
COLOR_BLUE='\033[0;34m'
COLOR_RESET='\033[0m'
# Determine the script directory in a portable way
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
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
# Extract the version number from the first line, e.g. "NVIM v0.9.1"
NVIM_VERSION=$(nvim --version | head -n 1 | sed -E 's/NVIM v([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
NVIM_MINOR_VERSION=$(echo "$NVIM_VERSION" | cut -d '.' -f2)
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
# Check for operating system and install dependencies accordingly
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "${COLOR_BLUE}Detected macOS. Installing dependencies for macOS...${COLOR_RESET}"
if ! command -v brew &>/dev/null; then
echo -e "${COLOR_RED}Homebrew is not installed! Please install Homebrew from https://brew.sh/ and try again.${COLOR_RESET}"
exit 1
fi
brew install ripgrep fd fzf tmux
elif [[ -f /etc/os-release ]]; then
DISTRO=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
case "$DISTRO" in
"arch"|"manjaro"|"endeavouros")
echo -e "${COLOR_BLUE}Installing dependencies for ${DISTRO}...${COLOR_RESET}"
sudo pacman -S --needed --noconfirm ripgrep fd fzf tmux
;;
"ubuntu"|"linuxmint")
echo -e "${COLOR_BLUE}Installing dependencies for ${DISTRO}...${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
else
echo -e "${COLOR_YELLOW}Unknown operating system. Please ensure required dependencies are installed manually.${COLOR_RESET}"
read -n1 -rep "Continue anyway (y) or quit (n): " CONTINUE_ANYWAY
if [[ ! $CONTINUE_ANYWAY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
}
neovim_setup() {
# NEOVIM SETUP #
echo -e "${COLOR_BLUE}Installing Neovim config...${COLOR_RESET}"
NVIM_DIR="$SCRIPT_DIR/nvim"
## BACKUP OLD 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
# Remove the old Neovim config directory
unlink ~/.config/nvim 2> /dev/null || rm -rf ~/.config/nvim
## DEFAULT PLUGINS ##
echo "Installing plugins..."
echo "You can remove the plugins you don't want from the ~/.config/nvim/lua/plugins directory"
## INSTALL CONFIG ##
ln -s "$NVIM_DIR" ~/.config/nvim
}
tmux_setup() {
# TMUX SETUP #
echo -e "${COLOR_BLUE}Installing tmux config...${COLOR_RESET}"
TMUX_DIR="$SCRIPT_DIR/tmux"
# Remove any old tmux config
unlink ~/.tmux.conf 2> /dev/null || rm -f ~/.tmux.conf
ln -s "$TMUX_DIR"/.tmux.conf ~/.tmux.conf
# Install tmux plugin manager if not already present
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"
echo ""
echo "if [ \"\$#\" -eq 0 ]; then"
echo " $TMUX_SESSIONIZER_PATH $SESSIONIZER_DIRS"
echo "elif [[ \"\$#\" -eq 2 && ( \$1 == \"--open\" || \$1 == \"-o\" ) ]]; then"
echo " $TMUX_SESSIONIZER_PATH --open \$2"
echo "elif [[ \"\$#\" -eq 2 && ( \$1 == \"--create\" || \$1 == \"-c\" ) ]]; then"
echo " names=($SESSIONIZER_DIRS)"
echo " selected=()"
echo " PS3=\"Choose the project directory: \""
echo " select name in \"\${names[@]}\" ; do"
echo " for reply in \$REPLY ; do"
echo " selected+=(\${names[reply - 1]})"
echo " done"
echo " [[ \$selected ]] && break"
echo " done"
echo " $TMUX_SESSIONIZER_PATH --create \$selected/\$2"
echo "fi"
} > ~/.local/bin/tmux-sessionizer
chmod +x ~/.local/bin/tmux-sessionizer
fi
}
post_install() {
# Post-install messages and font check
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 for the dev icons to display correctly.${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}Remember to add ~/.local/bin to your PATH variable to use the dev scripts.${COLOR_RESET}"
}
# Run the installation steps interactively:
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