cli-tools.sh RawHistoryFolder
1#!/bin/bash
2# cli-tools.sh — Install modern CLI toolkit (barebone, no DE or theme)
3set -euo pipefail
4
5LOG_FILE="/var/log/archup-first-boot.log"
6USERNAME=$(getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 && $1 != "nobody" {print $1; exit}')
7USER_HOME=$(getent passwd "$USERNAME" | cut -d: -f6)
8
9log() { echo "[cli-tools] $*" | tee -a "$LOG_FILE"; }
10
11if [[ -z "$USERNAME" ]]; then
12 log "ERROR: Could not detect user via getent passwd"
13 exit 1
14fi
15
16log "Installing modern CLI toolkit for $USERNAME..."
17
18log "Upgrading system and refreshing package databases..."
19pacman -Syu --noconfirm
20
21pacman -S --needed --noconfirm \
22 eza bat fd ripgrep fzf zoxide starship \
23 btop yazi git-delta gdu procs tealdeer \
24 lazygit atuin man-db neovim wget curl git
25
26log "Configuring shell environment for $USERNAME..."
27
28# Remove any previous archup block (idempotent re-run)
29if [ -f "$USER_HOME/.bashrc" ]; then
30 sed -i '/# BEGIN archup cli tools/,/# END archup cli tools/d' "$USER_HOME/.bashrc"
31fi
32
33# Append archup block
34cat >> "$USER_HOME/.bashrc" << 'BASHRC'
35# BEGIN archup cli tools
36# Aliases
37alias ls='eza --icons'
38alias ll='eza -la --icons --git'
39alias la='eza -a --icons'
40alias lt='eza --tree --icons'
41alias cat='bat'
42alias rg='rg --color=auto'
43alias fd='fd --color=auto'
44alias top='btop'
45alias vim='nvim'
46alias vi='nvim'
47
48# Git delta pager
49export GIT_PAGER='delta'
50
51# Man pages rendered with bat
52export MANPAGER="sh -c 'col -bx | bat -l man -p'"
53
54# fzf key bindings and fuzzy completion
55source <(fzf --bash) 2>/dev/null || true
56
57# zoxide (smart cd with frecency)
58eval "$(zoxide init bash)"
59[[ $- == *i* ]] && alias cd='z'
60
61# atuin (shell history search)
62eval "$(atuin init bash)" 2>/dev/null || true
63
64# starship prompt
65eval "$(starship init bash)"
66
67# ble.sh (Bash Line Editor) — must be sourced last
68[[ $- == *i* ]] && source -- ~/.local/share/blesh/ble.sh 2>/dev/null || true
69# END archup cli tools
70BASHRC
71
72chown "$USERNAME:$USERNAME" "$USER_HOME/.bashrc"
73
74# Deploy starship config
75mkdir -p "$USER_HOME/.config"
76cat > "$USER_HOME/.config/starship.toml" << 'STARSHIP'
77# Arch-inspired blue color scheme
78add_newline = true
79
80[username]
81show_always = true
82style_user = "fg:#87ceeb"
83style_root = "fg:#ff6b8a"
84format = "[$user]($style) "
85
86[hostname]
87disabled = true
88
89[directory]
90style = "fg:#e8f4f8"
91format = "in [$path]($style) "
92
93[git_branch]
94symbol = " "
95style = "fg:#6bb6d6"
96format = "on [$symbol$branch]($style) "
97
98[character]
99success_symbol = '[❯](fg:#6bb6d6)'
100error_symbol = '[✗](fg:#ff6b8a)'
101STARSHIP
102chown -R "$USERNAME:$USERNAME" "$USER_HOME/.config"
103
104# Update tldr cache
105sudo -u "$USERNAME" tldr --update 2>/dev/null || true
106
107# git delta global config
108sudo -u "$USERNAME" git config --global core.pager delta
109sudo -u "$USERNAME" git config --global interactive.diffFilter "delta --color-only"
110sudo -u "$USERNAME" git config --global delta.navigate true
111sudo -u "$USERNAME" git config --global delta.side-by-side true
112sudo -u "$USERNAME" git config --global merge.conflictstyle diff3
113sudo -u "$USERNAME" git config --global diff.colorMoved default
114
115log "CLI toolkit installed successfully."
116
117# Drop a one-shot hook into ~/.bash_profile so dms-opt-in.sh runs on first
118# interactive user login (after the system is fully up) and then removes itself.
119DMS_SCRIPT="/usr/local/share/archup/post-boot/dms-opt-in.sh"
120if [ -f "$DMS_SCRIPT" ]; then
121 touch "$USER_HOME/.bash_profile"
122 # Remove any stale archup-dms block (idempotent)
123 sed -i '/# BEGIN archup-dms first-login/,/# END archup-dms first-login/d' "$USER_HOME/.bash_profile"
124 cat >> "$USER_HOME/.bash_profile" << PROFILE
125# BEGIN archup-dms first-login
126if [ -f "$DMS_SCRIPT" ]; then
127 ARCHUP_USERNAME="$USERNAME" bash "$DMS_SCRIPT"
128fi
129sed -i '/# BEGIN archup-dms first-login/,/# END archup-dms first-login/d' ~/.bash_profile
130# END archup-dms first-login
131PROFILE
132 chown "$USERNAME:$USERNAME" "$USER_HOME/.bash_profile"
133 log "Registered dms-opt-in.sh to run on first user login."
134fi