irongit

refactor: use tput smcup/rmcup instead of animations

huncholanehuncholaneauthored
parent bf74857commit 00c47635b00c01e51fe5562a1599386240faa87cBrowse files

2 files changed, +155 -180

+9-11before_plugins.sh
@@ -1,13 +1,3 @@
1-zfunc_dir="$ZDOTDIR/.zfunc"
2-if [ ! -d "$zfunc_dir" ]; then mkdir -p "$zfunc_dir" &>/dev/null; fi
3-
4-add_completions() {
5- local file="$zfunc_dir/$1"
6- if [ ! -f "$file" ]; then
7- eval "$2" >"$file"
8- fi
9-}
10-
111 # Update PATH
122 export PATH="$PATH:$HOME/.local/bin:$HOME/go/bin:$HOME/.avm/bin:/usr/local/go/bin"
133 export PATH="$PATH:$HOME/.local/share/solana/install/active_release/bin"
@@ -19,7 +9,15 @@ export PATH="$HOME/.local/share/fnm:$PATH"
199 [ -f ~/.venv/bin/activate ] && . ~/.venv/bin/activate
2010 eval $(fnm env)
2111
22-# Create completions now that path is updated
12+# Create completions into ~/.config/.zfuncs directory
13+zfunc_dir="$ZDOTDIR/.zfunc"
14+if [ ! -d "$zfunc_dir" ]; then mkdir -p "$zfunc_dir" &>/dev/null; fi
15+add_completions() {
16+ local file="$zfunc_dir/$1"
17+ if [ ! -f "$file" ]; then
18+ eval "$2" >"$file"
19+ fi
20+}
2321 add_completions _fnm 'fnm completions --shell zsh'
2422 add_completions _rustup 'rustup completions zsh'
2523 add_completions _uv 'uv generate-shell-completion zsh'
+146-169install.sh
@@ -20,48 +20,12 @@ echoy() {
2020 echo -e "\e[33m$1\e[0m"
2121 }
2222
23-# Clock animation
24-BLA_clock=(๐Ÿ•› ๐Ÿ• ๐Ÿ•‘ ๐Ÿ•’ ๐Ÿ•“ ๐Ÿ•” ๐Ÿ•• ๐Ÿ•– ๐Ÿ•— ๐Ÿ•˜ ๐Ÿ•™ ๐Ÿ•š)
25-
2623 # Use $prefix for commands that might need sudo
2724 prefix="$([[ $(whoami) == "root" ]] && echo "" || echo "sudo")"
2825 LAST_OUTPUT=$(mktemp)
2926 [ -d "$HOME" ] || { echor "$HOME is not a directory. You are cancelled." && exit 1; }
3027 export PATH="$PATH:/usr/local/go/bin:/usr/local/go/bin:$HOME/go/bin:$HOME/.local/bin"
3128
32-# Ensure sudo and run command in background with animation, returns 1 if there was an issue
33-# $1: command used to check if the 2nd command should be ran ("" is always true)
34-# $2: command to run in the background
35-# $3: text to append to animation
36-# $4: success message
37-# $5: failure message (after LAST_OUTPUT)
38-# $6: Ignore output if set
39-animate() {
40- # Return when check is success
41- [[ -n "$1" ]] && eval "$1" && echob "โ„น๏ธ No action required. $4" && return 0
42-
43- # Ensure sudo
44- [[ "$(whoami)" == "root" ]] || sudo -v || exit 1
45-
46- # Run with output to tmp
47- eval "$2" &>"$LAST_OUTPUT" &
48-
49- # Wait and animate the command
50- local pid=$!
51- while kill -0 $pid 2>/dev/null; do
52- for frame in "${BLA_clock[@]}"; do
53- printf "\r%s %s " "${frame}" "$3"
54- sleep 0.2
55- done
56- done
57-
58- # Clear and output error if needed
59- printf "\033[2K\r"
60- { { wait $pid || [[ -n "$6" ]]; } && echog "โœ… $4"; } || { cat "$LAST_OUTPUT" && echor "\n๐Ÿ”ด $5" && return 1; }
61-}
62-
63-echo "Ensuring base tools are installed."
64-
6529 # Install basic tools on debian
6630 if [ -f /etc/debian_version ]; then
6731 # Set the installer prefix
@@ -70,18 +34,17 @@ if [ -f /etc/debian_version ]; then
7034
7135 # Update system
7236 echop "Detected Debian. Updating and upgrading now!"
73- animate "" \
74- "$installer update && $installer upgrade" \
75- "Updating system" \
76- "System up to date!" \
77- "Failed to update system" || exit 1
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; }
7841
7942 # Install build essential
80- animate "dpkg -s build-essential &>/dev/null" \
81- "$install_cmd build-essential" \
82- "Installing build-essential" \
83- "build-essential installed" \
84- "Failed to install build-essential" || exit 1
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; }
8548
8649 # Install basic tools for arch
8750 elif [ -f /etc/arch-release ]; then
@@ -90,167 +53,181 @@ elif [ -f /etc/arch-release ]; then
9053 install_cmd="$installer -S"
9154
9255 # Update system
93- echot "Arch Detected. You are elite. Updating and upgrading now!"
94- animate "" \
95- "$installer -Syu" \
96- "Updating system" \
97- "System up to date!" \
98- "Failed to update system" || exit 1
56+ { tput smcup &&
57+ eval "$installer -Syu" &&
58+ tput rmcup && echog "โœ… System up to date"; } ||
59+ { echor "Failed to update" && exit 1; }
9960
10061 # Install base-devel
101- animate "pacman -Q base-devel &>/dev/null" \
102- "$install_cmd base-devel" \
103- "Installing base-devel" \
104- "base-devel installed" \
105- "Failed to install base-devel" || exit 1
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; }
10667
10768 # Install git
108- animate "command -v git &>/dev/null" \
109- "$install_cmd git" \
110- "Installing git" \
111- "git installed" \
112- "Failed to install git" || exit 1
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; }
11376
11477 # Install cargo before paru
115- animate "[ -f ~/.cargo/env ]" \
116- "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" \
117- "Installing cargo" \
118- "cargo installed" \
119- "Failed to install cargo" || exit 1
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
12084
12185 # Install paru
12286 paru_dir="$(mktemp -d)"
123- # command -v paru &>/dev/null ||
124- # { rm -rf $HOME/paru && git clone https://aur.archlinux.org/paru.git $paru_dir && cd $paru_dir && makepkg -si; } ||
125- # { exit 1; }
126- animate "command -v paru &>/dev/null" \
127- "rm -rf $HOME/paru && git clone https://aur.archlinux.org/paru.git $paru_dir && cd $paru_dir && makepkg -si --noconfirm" \
128- "Installing paru" \
129- "paru installed" \
130- "Failed to install paru" || exit 1
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+ { echor "๐Ÿ”ด Failed to install paru" && exit 1; }
13192 fi
13293
13394 # Install zsh
134-animate "command -v zsh &>/dev/null" \
135- "$install_cmd zsh" \
136- "Installing zsh" \
137- "zsh installed" \
138- "Failed to install zsh" || exit 1
95+command -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; }
139100
140101 # Install curl (crazy but this happens sometimes)
141-animate "command -v curl &>/dev/null" \
142- "$install_cmd curl" \
143- "Installing curl" \
144- "curl installed" \
145- "Failed to install curl" || exit 1
102+command -v curl &>/dev/null && echob "โ˜‘๏ธ curl already installed" ||
103+ { tput smcup && echot "โ„น๏ธ Installing curl" &&
104+ eval "$install_cmd curl" &&
105+ tput rmcup && echog "โœ… curl installed"; } ||
106+ { echor "๐Ÿ”ด Failed to install curl" && exit 1; }
146107
147108 # Install unzip
148-animate "command -v unzip &>/dev/null" \
149- "$install_cmd unzip" \
150- "Installing unzip" \
151- "unzip installed" \
152- "Failed to install unzip" || exit 1
109+command -v unzip &>/dev/null && echob "โ˜‘๏ธ unzip already installed" ||
110+ { tput smcup && echot "โ„น๏ธ Installing unzip" &&
111+ eval "$install_cmd unzip" &&
112+ tput rmcup && echog "โœ… unzip installed"; } ||
113+ { echor "๐Ÿ”ด Failed to install unzip" && exit 1; }
153114
154115 # Install git
155-animate "command -v git &>/dev/null" \
156- "$install_cmd git" \
157- "Installing git" \
158- "git installed" \
159- "Failed to install git" || exit 1
116+command -v git &>/dev/null && echob "โ˜‘๏ธ git already installed" ||
117+ { tput smcup && echot "โ„น๏ธ Installing git" &&
118+ eval "$install_cmd git" &&
119+ tput rmcup && echog "โœ… git installed"; } ||
120+ { echor "๐Ÿ”ด Failed to install git" && exit 1; }
160121
161122 # Install cargo
162-animate "[ -f ~/.cargo/env ]" \
163- "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" \
164- "Installing cargo" \
165- "cargo installed" \
166- "Failed to install cargo" || exit 1
167-. ~/.cargo/env
123+[ -f ~/.cargo/env ] &>/dev/null && echob "โ˜‘๏ธ cargo already installed" ||
124+ { tput smcup && echot "โ„น๏ธ Installing cargo" &&
125+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y &&
126+ tput rmcup && echog "โœ… cargo installed"; } ||
127+ { echor "๐Ÿ”ด Failed to install cargo" && exit 1; }
128+. ~/.cargo/env # Source cargo
168129
169130 # Install lsd with cargo
170-animate "command -v lsd &>/dev/null" \
171- "cargo install lsd" \
172- "Installing lsd" \
173- "lsd installed" \
174- "Failed to install cargo" || exit 1
131+command -v lsd &>/dev/null && echob "โ˜‘๏ธ lsd already installed" ||
132+ { tput smcup && echot "โ„น๏ธ Installing lsd" &&
133+ cargo install lsd &&
134+ tput rmcup && echog "โœ… lsd installed"; } ||
135+ { echor "๐Ÿ”ด Failed to install lsd" && exit 1; }
175136
176137 # Install golang
138+current_go_version="$(go version 2>/dev/null | awk '{print $3}')"
177139 latest_go_version="$(curl -fsSL "https://go.dev/VERSION?m=text" | head -1)"
178-filename="$latest_go_version.$([[ "$(uname -m)" == "Linux" ]] && { printf "linux"; } || printf "darwin").$(uname -m).tar.gz"
179-animate "[[ \"$(go version 2>/dev/null | awk '{print $3}')\" == \"$latest_go_version\" ]]" \
180- "curl -fsSL https://go.dev/dl/go1.26.1.linux-amd64.tar.gz | $prefix tar xvzf - -C /usr/local" \
181- "Installing go" \
182- "go installed" \
183- "Failed to install go" || exit 1
140+case "$(uname -s)$(uname -m)" in
141+"Linuxx86_64") go_arch="linux-amd64" ;;
142+"Linuxaarch64") go_arch="linux-arm64" ;;
143+"Darwinx86_64") go_arch="darwin-amd64" ;;
144+"Darwinaarch64") go_arch="darwin-arm64" ;;
145+*) echor "unknown architecture, don't care" && exit 1 ;;
146+esac
147+filename="$latest_go_version.$go_arch.tar.gz"
148+[[ "$current_go_version" == "$latest_go_version" ]] &>/dev/null && echob "โ˜‘๏ธ go ($latest_go_version) already installed" ||
149+ { tput smcup && echot "โ„น๏ธ Installing go ($latest_go_version)" &&
150+ eval "$prefix rm -rf /usr/local/go && curl -fsSL https://go.dev/dl/$filename | $prefix tar xvzf - -C /usr/local" &&
151+ tput rmcup && echog "โœ… go installed"; } ||
152+ { echor "๐Ÿ”ด Failed to install go" && exit 1; }
184153
185154 # Install fzf (written in go)
186-animate "command -v fzf &>/dev/null" \
187- "git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install" \
188- "Installing fzf" \
189- "fzf installed" \
190- "Failed to install fzf"
155+[ -d ~/.fzf ] &>/dev/null && echob "โ˜‘๏ธ fzf already installed" ||
156+ { tput smcup && echot "โ„น๏ธ Installing fzf" &&
157+ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf && ~/.fzf/install --all &&
158+ tput rmcup && echog "โœ… fzf installed"; } ||
159+ { echor "๐Ÿ”ด Failed to install fzf" && exit 1; }
191160
192161 # Install lazygit with go
193-animate "command -v lazygit &>/dev/null" \
194- "go install github.com/jesseduffield/lazygit@latest" \
195- "Installing lazygit" \
196- "lazygit installed" \
197- "Failed to install lazygit" || exit 1
198-
199-# Install yazi
200-filename="yazi-$(uname -m)-$(
201- { [[ "$(uname -s)" == "Linux" ]] && printf "unknown-linux-%s" "$(ldd --version 2>&1 | grep -qi musl && echo musl || echo gnu)"; } || printf "apple-darwin"
202-).zip"
203-animate "[ -d /usr/local/yazi ]" \
204- "rm -rf /tmp/yazi* && $prefix rm -rf /usr/local/yazi &&
205- curl -fsSL https://github.com/sxyazi/yazi/releases/download/v26.1.22/yazi-x86_64-unknown-linux-gnu.zip -o /tmp/yazi.zip &&
206- unzip /tmp/yazi.zip -d /tmp && $prefix mv /tmp/yazi-x86_64-unknown-linux-gnu/ /usr/local/yazi/ && $prefix mv /usr/local/yazi/ya* /usr/local/bin" \
207- "Installing yazi" \
208- "yazi installed" \
209- "Failed to install yazi" || exit 1
210-
211-# Install fnm
212-animate "[ -d ~/.local/share/fnm ]" \
213- "curl -fsSL https://fnm.vercel.app/install | bash" \
214- "Installing fnm" \
215- "fnm installed" \
216- "Failed to install fnm" \
217- "ignore fail"
218-
219-# Install uv
220-animate "[ -f ~/.local/bin/uv ]" \
221- "curl -LsSf https://astral.sh/uv/install.sh | sh" \
222- "Installing uv" \
223- "uv installed" \
224- "Failed to install uv" || exit 1
162+command -v lazygit &>/dev/null && echob "โ˜‘๏ธ lazygit already installed" ||
163+ { tput smcup && echot "โ„น๏ธ Installing lazygit" &&
164+ go install github.com/jesseduffield/lazygit@latest &&
165+ tput rmcup && echog "โœ… lazygit installed"; } ||
166+ { echor "๐Ÿ”ด Failed to install lazygit" && exit 1; }
167+
168+# Install yazi if yazi command is found
169+# Download yazi zip for identified system build
170+# Move file contents into /usr/local/yazi (delete if existing)
171+# Move binaries into /usr/local/bin
172+case "$(uname -s)$(ldd --version | grep -o GNU)" in
173+"LinuxGNU") yazi_arch="unknown-linux-gnu" ;;
174+"Linux") yazi_arch="unknown-linux-musl" ;;
175+"Darwin") yazi_arch="apple-darwin" ;;
176+esac
177+yazi_stem="yazi-$(uname -m)-$yazi_arch"
178+yazi_link="https://github.com/sxyazi/yazi/releases/download/v26.1.22/$yazi_stem.zip"
179+yazi_tmp_dir="$(mktemp -d)"
180+yazi_zip_path="$yazi_tmp_dir/yazi.zip"
181+command -v yazi &>/dev/null && echob "โ˜‘๏ธ yazi already installed" ||
182+ { tput smcup && echot "โ„น๏ธ Installing yazi" &&
183+ eval "$prefix rm -rf /usr/local/yazi && curl -fsSL $yazi_link -o $yazi_zip_path &&
184+ unzip $yazi_zip_path -d $yazi_tmp_dir && $prefix mv $yazi_tmp_dir/$yazi_stem /usr/local/yazi &&
185+ $prefix mv -f /usr/local/yazi/* /usr/local/bin" &&
186+ tput rmcup && echog "โœ… yazi installed"; } ||
187+ { echor "๐Ÿ”ด Failed to install yazi" && exit 1; }
188+
189+# Install fnm if the directory does not already exist at ~/.local/share/fnm
190+[ -d ~/.local/share/fnm ] &>/dev/null && echob "โ˜‘๏ธ fnm already installed" ||
191+ { tput smcup && echot "โ„น๏ธ Installing fnm" &&
192+ curl -fsSL https://fnm.vercel.app/install | bash 2>&1 | grep -Pq "Could not infer shell type|open a new terminal" &&
193+ tput rmcup && echog "โœ… fnm installed"; } ||
194+ { echor "๐Ÿ”ด Failed to install fnm" && exit 1; }
195+
196+# Install uv if the binary does not exist yet at ~/.local/bin/uv
197+[ -f ~/.local/bin/uv ] &>/dev/null && echob "โ˜‘๏ธ uv already installed" ||
198+ { tput smcup && echot "โ„น๏ธ Installing uv" &&
199+ curl -LsSf https://astral.sh/uv/install.sh | sh &&
200+ tput rmcup && echog "โœ… uv installed"; } ||
201+ { echor "๐Ÿ”ด Failed to install uv" && exit 1; }
202+
203+# Create uv venv in home directory if one does not exist
225204 [ -f ~/.venv/bin/activate ] || (cd ~ && uv venv &>/dev/null)
226205
227206 # Install zoxide
228-animate "[ -f ~/.local/bin/zoxide ]" \
229- "curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh" \
230- "Installing zoxide" \
231- "zoxide installed" \
232- "Failed to install zoxide"
207+[ -f ~/.local/bin/zoxide ] && echob "โ˜‘๏ธ zoxide already installed" ||
208+ { tput smcup && echot "โ„น๏ธ Installing zoxide" &&
209+ curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh &&
210+ tput rmcup && echog "โœ… zoxide installed"; } ||
211+ { echor "๐Ÿ”ด Failed to install zoxide" && exit 1; }
233212
234213 # Create backups
235214 [ -d ~/.config ] || mkdir -p ~/.config
236-[ -f ~/.zshrc ] && mv ~/.zshrc ~/.zshrc.bak && echot "Backup ~/.zshrc -> ~/.zshrc.bak"
237-[ -f ~/.zshenv ] && mv ~/.zshenv ~/.zshenv.bak && echot "Backup ~/.zshenv -> ~/.zshenv.bak"
238-[ -d ~/.config/zsh ] && rm -rf ~/.config/zsh.bak && mv ~/.config/zsh ~/.config/zsh.bak
215+[ -f ~/.zshrc ] && mv ~/.zshrc ~/.zshrc.bak && echot "โ„น๏ธ Backup ~/.zshrc -> ~/.zshrc.bak"
216+[ -f ~/.zshenv ] && mv ~/.zshenv ~/.zshenv.bak && echot "โ„น๏ธ Backup ~/.zshenv -> ~/.zshenv.bak"
217+[ -d ~/.config/zsh ] && rm -rf ~/.config/zsh.bak && mv ~/.config/zsh ~/.config/zsh.bak && echot "โ„น๏ธ Backup ~/.config/zsh -> ~/.config/zsh.bak"
239218
240219 # Clone config repo
241-echo 'export ZDOTDIR=$HOME/.config/zsh' >~/.zshenv
220+echo 'export ZDOTDIR=$HOME/.config/zsh' >~/.zshenv && echot "โ„น๏ธ Set ZDOTDIR TO ~/.config/zsh"
242221 export ZDOTDIR=$HOME/.config/zsh
243-animate "" \
244- "git clone https://github.com/huncholane/dotzsh ~/.config/zsh" \
245- "Cloning dotzsh" \
246- "dotzsh cloned. Just a few more things." \
247- "Failed to clone dotzsh" || exit 1
222+{ tput smcup && echot "โ„น๏ธ Cloning dotzsh into ~/.config/zsh" &&
223+ git clone --depth=1 https://github.com/huncholane/dotzsh ~/.config/zsh &&
224+ tput rmcup && echog "โœ… dotzsh cloned to ~/.config/zsh"; } ||
225+ { echor "๐Ÿ”ด Failed to clone dotzsh into ~/.config/zsh" && exit 1; }
248226
249227 # Install antidote
250-animate "[ -d ~/.config/zsh/.antidote ]" \
251- "git clone --depth=1 https://github.com/mattmc3/antidote.git ${ZDOTDIR:-~}/.antidote" \
252- "Installing antidote" \
253- "antidote installed" \
254- "Failed to install antidote" || exit 1
228+{ tput smcup && echot "โ„น๏ธ Cloning antidote into ~/.config/zsh/.antidote" &&
229+ git clone --depth=1 https://github.com/mattmc3/antidote.git ${ZDOTDIR:-~}/.antidote &&
230+ tput rmcup && echog "โœ… antidote installed"; }
255231
256-echot "\nRun 'exec zsh' to see the magic"
232+# echot "\n๐Ÿš€ Run 'exec zsh' to see the magic"
233+exec zsh