irongit
dotzsh/install.sh
234 lines10 KBBourne Again Shell (bash)
1#!/bin/bash
2
3# Colored echos
4echop() {
5 echo -e "\033[35m$1\033[0m"
6}
7echor() {
8 echo -e "\033[31m$1\033[0m"
9}
10echog() {
11 echo -e "\033[32m$1\033[0m"
12}
13echot() {
14 echo -e "\033[36m$1\033[0m"
15}
16echob() {
17 echo -e "\033[34m$1\033[0m"
18}
19echoy() {
20 echo -e "\033[33m$1\033[0m"
21}
22
23# Use $prefix for commands that might need sudo
24prefix="$([[ $(whoami) == "root" ]] && echo "" || echo "sudo")"
25LAST_OUTPUT=$(mktemp)
26[ -d "$HOME" ] || { echor "$HOME is not a directory. You are cancelled." && exit 1; }
27export PATH="$PATH:/usr/local/go/bin:/usr/local/go/bin:$HOME/go/bin:$HOME/.local/bin"
28
29# Install basic tools on debian
30if [ -f /etc/debian_version ]; then
31 # Set the installer prefix
32 installer="$prefix apt-get -y"
33 install_cmd="$installer install"
34
35 # Update system
36 echop "Detected Debian. Updating and upgrading now!"
37 { tput smcup && echot "ℹ️ Updating system" &&
38 eval "$installer update && $installer upgrade" &&
39 tput rmcup && echog "✅ System up to date"; } ||
40 { echor "🔴 Failed to update system" && exit 1; }
41
42 # Install build essential
43 dpkg -s build-essential &>/dev/null && echot "☑️ build-essential already installed" ||
44 { tput smcup && echot "ℹ️ Installing build-essential" &&
45 eval "$install_cmd build-essential" &&
46 tput rmcup && echog "✅ build-essential installed"; } ||
47 { echor "🔴 Failed to install build-essential" && exit 1; }
48
49# Install basic tools for arch
50elif [ -f /etc/arch-release ]; then
51 # Set pacman prefix
52 installer="$prefix pacman --noconfirm"
53 install_cmd="$installer -S"
54
55 # Update system
56 { tput smcup &&
57 eval "$installer -Syu" &&
58 tput rmcup && echog "✅ System up to date"; } ||
59 { echor "Failed to update" && exit 1; }
60
61 # Install base-devel
62 pacman -Q base-devel &>/dev/null && echob "☑️ base-devel already installed" ||
63 { tput smcup &&
64 eval "$install_cmd base-devel" && echot "ℹ️ Installing base-devel" &&
65 tput rmcup && echog "✅ base-devel installed"; } ||
66 { echor "🔴 Failed to install base-devel" && exit 1; }
67
68 # Install git
69 command -v git &>/dev/null && echob "☑️ git already installed" ||
70 {
71 tput smcup && echot "ℹ️ Installing git" &&
72 eval "$install_cmd git" &&
73 tput rmcup && echog "✅ git installed"
74 } ||
75 { echor "🔴 Failed to install git" && exit 1; }
76
77 # Install cargo before paru
78 [ -f ~/.cargo/env ] && echob "☑️ cargo already installed" ||
79 { tput smcup && echot "ℹ️ Installing cargo" &&
80 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y &&
81 tput rmcup && echog "✅ cargo installed"; } ||
82 { echor "🔴 Failed to install cargo" && exit 1; }
83 . ~/.cargo/env # Source cargo
84
85 # Install paru
86 paru_dir="$(mktemp -d)"
87 command -v paru &>/dev/null && echob "☑️ paru already installed" ||
88 { tput smcup && echot "ℹ️ Installing paru" &&
89 rm -rf $HOME/paru && git clone https://aur.archlinux.org/paru.git $paru_dir && cd $paru_dir && makepkg -si --noconfirm &&
90 tput rmcup && echog "✅ paru installed"; } ||
91 { tput rmcup && echor "🔴 Failed to install paru"; }
92fi
93
94# Install zsh
95command -v zsh &>/dev/null && echob "☑️ zsh already installed" ||
96 { tput smcup && echot "ℹ️ Installing zsh" &&
97 eval "$install_cmd zsh" &&
98 tput rmcup && echog "✅ zsh installed"; } ||
99 { echor "🔴 Failed to install zsh" && exit 1; }
100chsh -s /usr/bin/zsh &>/dev/null && echot "ℹ️ Set default shell to zsh"
101
102# Install curl (crazy but this happens sometimes)
103command -v curl &>/dev/null && echob "☑️ curl already installed" ||
104 { tput smcup && echot "ℹ️ Installing curl" &&
105 eval "$install_cmd curl" &&
106 tput rmcup && echog "✅ curl installed"; } ||
107 { echor "🔴 Failed to install curl" && exit 1; }
108
109# Install unzip
110command -v unzip &>/dev/null && echob "☑️ unzip already installed" ||
111 { tput smcup && echot "ℹ️ Installing unzip" &&
112 eval "$install_cmd unzip" &&
113 tput rmcup && echog "✅ unzip installed"; } ||
114 { echor "🔴 Failed to install unzip" && exit 1; }
115
116# Install git
117command -v git &>/dev/null && echob "☑️ git already installed" ||
118 { tput smcup && echot "ℹ️ Installing git" &&
119 eval "$install_cmd git" &&
120 tput rmcup && echog "✅ git installed"; } ||
121 { echor "🔴 Failed to install git" && exit 1; }
122
123# Install cargo
124[ -f ~/.cargo/env ] &>/dev/null && echob "☑️ cargo already installed" ||
125 { tput smcup && echot "ℹ️ Installing cargo" &&
126 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y &&
127 tput rmcup && echog "✅ cargo installed"; } ||
128 { echor "🔴 Failed to install cargo" && exit 1; }
129. ~/.cargo/env # Source cargo
130
131# Install lsd with cargo
132command -v lsd &>/dev/null && echob "☑️ lsd already installed" ||
133 { tput smcup && echot "ℹ️ Installing lsd" &&
134 cargo install lsd &&
135 tput rmcup && echog "✅ lsd installed"; } ||
136 { echor "🔴 Failed to install lsd" && exit 1; }
137
138# Install golang
139current_go_version="$(go version 2>/dev/null | awk '{print $3}')"
140latest_go_version="$(curl -fsSL "https://go.dev/VERSION?m=text" | head -1)"
141case "$(uname -s)$(uname -m)" in
142"Linuxx86_64") go_arch="linux-amd64" ;;
143"Linuxarm64") go_arch="linux-arm64" ;;
144"Darwinx86_64") go_arch="darwin-amd64" ;;
145"Darwinarm64") go_arch="darwin-arm64" ;;
146*) echor "unknown architecture, don't care" && exit 1 ;;
147esac
148filename="$latest_go_version.$go_arch.tar.gz"
149[[ "$current_go_version" == "$latest_go_version" ]] &>/dev/null && echob "☑️ go ($latest_go_version) already installed" ||
150 { tput smcup && echot "ℹ️ Installing go ($latest_go_version)" &&
151 eval "$prefix rm -rf /usr/local/go && curl -fsSL https://go.dev/dl/$filename | $prefix tar xvzf - -C /usr/local" &&
152 tput rmcup && echog "✅ go installed"; } ||
153 { echor "🔴 Failed to install go" && exit 1; }
154
155# Install fzf (written in go)
156[ -d ~/.fzf ] &>/dev/null && echob "☑️ fzf already installed" ||
157 { tput smcup && echot "ℹ️ Installing fzf" &&
158 git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install --all &&
159 tput rmcup && echog "✅ fzf installed"; } ||
160 { echor "🔴 Failed to install fzf" && exit 1; }
161
162# Install lazygit with go
163command -v lazygit &>/dev/null && echob "☑️ lazygit already installed" ||
164 { tput smcup && echot "ℹ️ Installing lazygit" &&
165 go install github.com/jesseduffield/lazygit@latest &&
166 tput rmcup && echog "✅ lazygit installed"; } ||
167 { echor "🔴 Failed to install lazygit" && exit 1; }
168
169# Install yazi if yazi command is found
170# Download yazi zip for identified system build
171# Move file contents into /usr/local/yazi (delete if existing)
172# Move binaries into /usr/local/bin
173case "$(uname -s)$(ldd --version | grep -o GNU)" in
174"LinuxGNU") yazi_arch="unknown-linux-gnu" ;;
175"Linux") yazi_arch="unknown-linux-musl" ;;
176"Darwin") yazi_arch="apple-darwin" ;;
177esac
178yazi_stem="yazi-$(uname -m)-$yazi_arch"
179yazi_link="https://github.com/sxyazi/yazi/releases/download/v26.1.22/$yazi_stem.zip"
180yazi_tmp_dir="$(mktemp -d)"
181yazi_zip_path="$yazi_tmp_dir/yazi.zip"
182command -v yazi &>/dev/null && echob "☑️ yazi already installed" ||
183 { tput smcup && echot "ℹ️ Installing yazi" &&
184 eval "$prefix rm -rf /usr/local/yazi && curl -fsSL $yazi_link -o $yazi_zip_path &&
185 unzip $yazi_zip_path -d $yazi_tmp_dir && $prefix mv $yazi_tmp_dir/$yazi_stem /usr/local/yazi &&
186 $prefix mv -f /usr/local/yazi/* /usr/local/bin" &&
187 tput rmcup && echog "✅ yazi installed"; } ||
188 { echor "🔴 Failed to install yazi" && exit 1; }
189
190# Install fnm if the directory does not already exist at ~/.local/share/fnm
191[ -d ~/.local/share/fnm ] &>/dev/null && echob "☑️ fnm already installed" ||
192 { tput smcup && echot "ℹ️ Installing fnm" &&
193 curl -fsSL https://fnm.vercel.app/install | bash 2>&1 | grep -Pq "Could not infer shell type|open a new terminal" &&
194 tput rmcup && echog "✅ fnm installed"; } ||
195 { echor "🔴 Failed to install fnm" && exit 1; }
196
197# Install uv if the binary does not exist yet at ~/.local/bin/uv
198[ -f ~/.local/bin/uv ] &>/dev/null && echob "☑️ uv already installed" ||
199 { tput smcup && echot "ℹ️ Installing uv" &&
200 curl -LsSf https://astral.sh/uv/install.sh | sh &&
201 tput rmcup && echog "✅ uv installed"; } ||
202 { echor "🔴 Failed to install uv" && exit 1; }
203
204# Create uv venv in home directory if one does not exist
205[ -f ~/.venv/bin/activate ] || (cd ~ && uv venv &>/dev/null)
206
207# Install zoxide
208[ -f ~/.local/bin/zoxide ] && echob "☑️ zoxide already installed" ||
209 { tput smcup && echot "ℹ️ Installing zoxide" &&
210 curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh &&
211 tput rmcup && echog "✅ zoxide installed"; } ||
212 { echor "🔴 Failed to install zoxide" && exit 1; }
213
214# Create backups
215[ -d ~/.config ] || mkdir -p ~/.config
216[ -f ~/.zshrc ] && mv ~/.zshrc ~/.zshrc.bak && echot "ℹ️ Backup ~/.zshrc -> ~/.zshrc.bak"
217[ -f ~/.zshenv ] && mv ~/.zshenv ~/.zshenv.bak && echot "ℹ️ Backup ~/.zshenv -> ~/.zshenv.bak"
218[ -d ~/.config/zsh ] && rm -rf ~/.config/zsh.bak && mv ~/.config/zsh ~/.config/zsh.bak && echot "ℹ️ Backup ~/.config/zsh -> ~/.config/zsh.bak"
219
220# Clone config repo
221echo 'export ZDOTDIR=$HOME/.config/zsh' >~/.zshenv && echot "ℹ️ Set ZDOTDIR TO ~/.config/zsh"
222export ZDOTDIR=$HOME/.config/zsh
223{ tput smcup && echot "ℹ️ Cloning dotzsh into ~/.config/zsh" &&
224 git clone --depth=1 https://github.com/huncholane/dotzsh ~/.config/zsh &&
225 tput rmcup && echog "✅ dotzsh cloned to ~/.config/zsh"; } ||
226 { echor "🔴 Failed to clone dotzsh into ~/.config/zsh" && exit 1; }
227
228# Install antidote
229{ tput smcup && echot "ℹ️ Cloning antidote into ~/.config/zsh/.antidote" &&
230 git clone --depth=1 https://github.com/mattmc3/antidote.git ${ZDOTDIR:-~}/.antidote &&
231 tput rmcup && echog "✅ antidote installed"; }
232
233# Start new shell with everything installed
234exec zsh