Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·518 lines (446 loc) · 16.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·518 lines (446 loc) · 16.3 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
#!/bin/bash
#
# ╔══════════════════════════════════════════════════════════════════════════╗
# ║ DOTFILES INSTALLER ║
# ║ ║
# ║ Configura automaticamente: ║
# ║ • Alacritty (terminal GPU-accelerated) ║
# ║ • tmux (multiplexador de terminal) ║
# ║ • Vim (editor com plugins) ║
# ║ • Fonte JetBrains Mono ║
# ║ ║
# ║ Tema: Catppuccin Mocha ║
# ║ ║
# ║ Compatível com: Ubuntu/Debian, Fedora, Arch, macOS ║
# ╚══════════════════════════════════════════════════════════════════════════╝
#
# USO:
# chmod +x install.sh
# ./install.sh
#
# OPÇÕES:
# ./install.sh --help Mostra esta ajuda
# ./install.sh --dry-run Simula sem instalar
#
set -e
# ============================================================================
# CONFIGURAÇÃO
# ============================================================================
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DRY_RUN=false
# Cores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# ============================================================================
# FUNÇÕES AUXILIARES
# ============================================================================
print_header() {
echo ""
echo -e "${PURPLE}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${PURPLE}║${NC}${BOLD} DOTFILES INSTALLER ${PURPLE}║${NC}"
echo -e "${PURPLE}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
print_step() {
echo -e "${BLUE}==>${NC} ${BOLD}$1${NC}"
}
print_substep() {
echo -e " ${CYAN}→${NC} $1"
}
print_success() {
echo -e " ${GREEN}✓${NC} $1"
}
print_warning() {
echo -e " ${YELLOW}!${NC} $1"
}
print_error() {
echo -e " ${RED}✗${NC} $1"
}
print_help() {
echo "USO: ./install.sh [opções]"
echo ""
echo "OPÇÕES:"
echo " --help Mostra esta ajuda"
echo " --dry-run Simula a instalação sem fazer alterações"
echo ""
echo "O QUE SERÁ INSTALADO:"
echo " • Dependências: tmux, vim, fzf, ripgrep, xclip"
echo " • Fonte: JetBrains Mono"
echo " • Configs: Alacritty, tmux, Vim"
echo " • Tema: Catppuccin Mocha"
echo ""
echo "ATALHOS PRINCIPAIS:"
echo " • Ctrl+a h Cheatsheet (dentro do tmux)"
echo " • Ctrl+a | Dividir terminal vertical"
echo " • Ctrl+a - Dividir terminal horizontal"
echo " • Espaço+f Buscar arquivos (vim)"
echo ""
}
run_cmd() {
if [ "$DRY_RUN" = true ]; then
echo -e " ${YELLOW}[dry-run]${NC} $*"
else
"$@"
fi
}
# ============================================================================
# DETECÇÃO DO SISTEMA
# ============================================================================
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [ -f /etc/os-release ]; then
. /etc/os-release
echo "$ID"
else
echo "unknown"
fi
}
detect_pkg_manager() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "brew"
elif command -v apt &> /dev/null; then
echo "apt"
elif command -v dnf &> /dev/null; then
echo "dnf"
elif command -v pacman &> /dev/null; then
echo "pacman"
else
echo "unknown"
fi
}
# ============================================================================
# INSTALAÇÃO DE PACOTES
# ============================================================================
install_pkg() {
local pkg="$1"
local pkg_apt="${2:-$pkg}"
local pkg_dnf="${3:-$pkg}"
local pkg_pacman="${4:-$pkg}"
local pkg_brew="${5:-$pkg}"
case $PKG_MANAGER in
apt)
run_cmd sudo apt install -y "$pkg_apt"
;;
dnf)
run_cmd sudo dnf install -y "$pkg_dnf"
;;
pacman)
run_cmd sudo pacman -S --noconfirm "$pkg_pacman"
;;
brew)
run_cmd brew install "$pkg_brew"
;;
*)
print_warning "Instale manualmente: $pkg"
return 1
;;
esac
}
install_if_missing() {
local cmd="$1"
local name="${2:-$cmd}"
shift 2
if command -v "$cmd" &> /dev/null; then
print_success "$name já instalado"
return 0
fi
print_substep "Instalando $name..."
if install_pkg "$@"; then
print_success "$name instalado"
else
print_error "Falha ao instalar $name"
return 1
fi
}
# ============================================================================
# INSTALAÇÃO DA FONTE
# ============================================================================
install_font() {
print_step "Instalando fonte JetBrains Mono..."
# Verifica se já está instalada
if fc-list 2>/dev/null | grep -qi "JetBrains Mono"; then
print_success "JetBrains Mono já instalada"
return 0
fi
# Diretório de fontes
if [[ "$OSTYPE" == "darwin"* ]]; then
FONT_DIR="$HOME/Library/Fonts"
else
FONT_DIR="$HOME/.local/share/fonts"
fi
run_cmd mkdir -p "$FONT_DIR"
# Copia as fontes do repositório
if [ -d "$DOTFILES_DIR/fonts" ]; then
print_substep "Copiando fontes do repositório..."
run_cmd cp "$DOTFILES_DIR/fonts/"*.ttf "$FONT_DIR/"
# Atualiza cache (Linux)
if [[ "$OSTYPE" != "darwin"* ]]; then
run_cmd fc-cache -f
fi
print_success "JetBrains Mono instalada"
else
print_warning "Pasta fonts/ não encontrada, instalando via gerenciador..."
case $PKG_MANAGER in
apt)
run_cmd sudo apt install -y fonts-jetbrains-mono
;;
dnf)
run_cmd sudo dnf install -y jetbrains-mono-fonts
;;
pacman)
run_cmd sudo pacman -S --noconfirm ttf-jetbrains-mono
;;
brew)
run_cmd brew install --cask font-jetbrains-mono
;;
esac
fi
}
# ============================================================================
# INSTALAÇÃO DO ALACRITTY
# ============================================================================
install_alacritty() {
print_step "Verificando Alacritty..."
if command -v alacritty &> /dev/null; then
print_success "Alacritty já instalado ($(alacritty --version 2>/dev/null | head -1))"
return 0
fi
print_substep "Alacritty não encontrado"
case $PKG_MANAGER in
apt)
print_warning "No Ubuntu/Debian, instale via:"
echo " sudo add-apt-repository ppa:aslatter/ppa"
echo " sudo apt install alacritty"
echo " Ou: cargo install alacritty"
;;
pacman)
print_substep "Instalando via pacman..."
run_cmd sudo pacman -S --noconfirm alacritty
;;
brew)
print_substep "Instalando via Homebrew..."
run_cmd brew install --cask alacritty
;;
dnf)
print_warning "No Fedora, instale via: sudo dnf install alacritty"
echo " Ou: cargo install alacritty"
;;
*)
print_warning "Instale Alacritty manualmente: cargo install alacritty"
;;
esac
}
# ============================================================================
# CONFIGURAÇÃO DOS SYMLINKS
# ============================================================================
setup_symlinks() {
print_step "Configurando symlinks..."
# Criar diretórios necessários
run_cmd mkdir -p ~/.config/alacritty
run_cmd mkdir -p ~/.config/tmux
# Função para criar symlink com backup
create_symlink() {
local src="$1"
local dest="$2"
local name="$3"
# Se já é um symlink correto, pula
if [ -L "$dest" ] && [ "$(readlink "$dest")" = "$src" ]; then
print_success "$name já configurado"
return 0
fi
# Backup se existir arquivo real
if [ -f "$dest" ] && [ ! -L "$dest" ]; then
print_substep "Backup: $dest → $dest.bak"
run_cmd mv "$dest" "$dest.bak"
fi
# Remove symlink antigo se existir
[ -L "$dest" ] && run_cmd rm "$dest"
# Cria novo symlink
run_cmd ln -sf "$src" "$dest"
print_success "$name → $dest"
}
create_symlink "$DOTFILES_DIR/alacritty/alacritty.toml" ~/.config/alacritty/alacritty.toml "Alacritty"
create_symlink "$DOTFILES_DIR/tmux/.tmux.conf" ~/.tmux.conf "tmux"
create_symlink "$DOTFILES_DIR/vim/.vimrc" ~/.vimrc "Vim"
# Scripts do tmux (diretório)
if [ -L ~/.config/tmux/scripts ]; then
run_cmd rm ~/.config/tmux/scripts
elif [ -d ~/.config/tmux/scripts ]; then
run_cmd rm -rf ~/.config/tmux/scripts
fi
run_cmd ln -sf "$DOTFILES_DIR/tmux/scripts" ~/.config/tmux/scripts
print_success "tmux scripts → ~/.config/tmux/scripts"
}
# ============================================================================
# VIM PLUGINS
# ============================================================================
setup_vim() {
print_step "Configurando Vim..."
# Instala vim-plug se necessário
if [ ! -f ~/.vim/autoload/plug.vim ]; then
print_substep "Instalando vim-plug..."
run_cmd curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
print_success "vim-plug instalado"
else
print_success "vim-plug já instalado"
fi
# Instala plugins
print_substep "Instalando plugins do Vim..."
if [ "$DRY_RUN" = false ]; then
vim +PlugInstall +qall 2>/dev/null || true
fi
print_success "Plugins instalados"
}
# ============================================================================
# CONFIGURAÇÕES DO SISTEMA (Linux)
# ============================================================================
setup_linux_extras() {
if [[ "$OSTYPE" == "darwin"* ]]; then
return 0
fi
print_step "Configurações extras (Linux)..."
# Terminal padrão
if command -v alacritty &> /dev/null; then
ALACRITTY_PATH=$(which alacritty)
print_substep "Configurando Alacritty como terminal padrão..."
run_cmd sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator "$ALACRITTY_PATH" 50 2>/dev/null || true
run_cmd sudo update-alternatives --set x-terminal-emulator "$ALACRITTY_PATH" 2>/dev/null || true
print_success "Terminal padrão configurado"
fi
# Entrada no menu
if command -v alacritty &> /dev/null && [ ! -f ~/.local/share/applications/alacritty.desktop ]; then
print_substep "Criando entrada no menu..."
run_cmd mkdir -p ~/.local/share/applications
if [ "$DRY_RUN" = false ]; then
cat > ~/.local/share/applications/alacritty.desktop << EOF
[Desktop Entry]
Type=Application
Name=Alacritty
GenericName=Terminal
Comment=Terminal emulator
Exec=$(which alacritty)
Icon=utilities-terminal
Terminal=false
Categories=System;TerminalEmulator;
Keywords=terminal;shell;
EOF
update-desktop-database ~/.local/share/applications/ 2>/dev/null || true
fi
print_success "Entrada no menu criada"
fi
}
# ============================================================================
# CONFIGURAÇÕES DO SISTEMA (macOS)
# ============================================================================
setup_macos_extras() {
if [[ "$OSTYPE" != "darwin"* ]]; then
return 0
fi
print_step "Configurações extras (macOS)..."
# Verifica Homebrew
if ! command -v brew &> /dev/null; then
print_warning "Homebrew não encontrado!"
echo " Instale via: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
return 1
fi
print_success "Homebrew OK"
}
# ============================================================================
# SUMÁRIO FINAL
# ============================================================================
print_summary() {
echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║${NC}${BOLD} INSTALAÇÃO CONCLUÍDA! ${GREEN}║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BOLD}Próximos passos:${NC}"
echo ""
echo " 1. Reinicie o terminal (ou abra o Alacritty)"
echo ""
echo " 2. Inicie o tmux:"
echo -e " ${CYAN}tmux${NC}"
echo ""
echo " 3. Veja o cheatsheet:"
echo -e " ${CYAN}Ctrl+a h${NC}"
echo ""
echo -e "${BOLD}Atalhos principais:${NC}"
echo ""
echo " Alacritty:"
echo " Ctrl+V Colar"
echo " Ctrl+Shift+F Buscar"
echo " Ctrl+Shift+Space Modo Vi (navegar)"
echo ""
echo " tmux (prefixo: Ctrl+a):"
echo " Ctrl+a | Dividir vertical"
echo " Ctrl+a - Dividir horizontal"
echo " Ctrl+a h Cheatsheet"
echo " Alt+setas Navegar painéis"
echo ""
echo " Vim (leader: Espaço):"
echo " Espaço+f Buscar arquivos"
echo " Espaço+/ Buscar conteúdo"
echo " gcc Comentar linha"
echo ""
}
# ============================================================================
# MAIN
# ============================================================================
main() {
# Parse argumentos
for arg in "$@"; do
case $arg in
--help|-h)
print_help
exit 0
;;
--dry-run)
DRY_RUN=true
;;
esac
done
print_header
# Detecta sistema
OS=$(detect_os)
PKG_MANAGER=$(detect_pkg_manager)
echo -e " ${BOLD}Sistema:${NC} $OS"
echo -e " ${BOLD}Pacotes:${NC} $PKG_MANAGER"
if [ "$DRY_RUN" = true ]; then
echo -e " ${BOLD}Modo:${NC} ${YELLOW}dry-run (simulação)${NC}"
fi
echo ""
# Instalação
print_step "Instalando dependências..."
install_if_missing "tmux" "tmux" "tmux"
install_if_missing "vim" "Vim" "vim"
install_if_missing "fzf" "fzf" "fzf"
install_if_missing "rg" "ripgrep" "ripgrep" "ripgrep" "ripgrep" "ripgrep"
if [[ "$OSTYPE" != "darwin"* ]]; then
install_if_missing "xclip" "xclip" "xclip"
fi
install_font
install_alacritty
setup_symlinks
setup_vim
if [[ "$OSTYPE" == "darwin"* ]]; then
setup_macos_extras
else
setup_linux_extras
fi
if [ "$DRY_RUN" = false ]; then
print_summary
else
echo ""
echo -e "${YELLOW}[dry-run] Simulação concluída. Nenhuma alteração foi feita.${NC}"
echo ""
fi
}
main "$@"