-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·127 lines (111 loc) · 3.6 KB
/
install.sh
File metadata and controls
executable file
·127 lines (111 loc) · 3.6 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
#!/usr/bin/env bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
log_info() { printf "${GREEN}[INFO]${NC} %s\n" "$1"; }
log_warn() { printf "${YELLOW}[WARN]${NC} %s\n" "$1"; }
log_error() { printf "${RED}[ERROR]${NC} %s\n" "$1"; }
detect_platform() {
case "$OSTYPE" in
darwin*) echo "macos" ;;
linux*) echo "linux" ;;
msys* | cygwin* | mingw*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLATFORM=$(detect_platform)
log_info "Dotfiles installer starting"
log_info "Platform: $PLATFORM"
# =========================
# SECTION: CONFIG PATHS
# =========================
KITTY_CONFIG="$DOTFILES_DIR/config/kitty"
STARSHIP_CONFIG="$DOTFILES_DIR/config/starship/starship.toml"
NVIM_CONFIG="$DOTFILES_DIR/config/nvim"
WIN_TERMINAL_CONFIG="$DOTFILES_DIR/config/windowsterminal/settings.json"
BASH_RC="$DOTFILES_DIR/config/.bashrc"
ZSH_RC="$DOTFILES_DIR/config/.zshrc"
# =========================
# SECTION: CONFIG MAPPINGS
# =========================
# Define configs as: "target|source"
if [[ "$PLATFORM" == "windows" ]]; then
CONFIGS=(
"$LOCALAPPDATA/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json|$WIN_TERMINAL_CONFIG"
"$APPDATA/starship.toml|$STARSHIP_CONFIG"
"$LOCALAPPDATA/nvim|$NVIM_CONFIG"
"$USERPROFILE/.bashrc|$BASH_RC"
)
elif [[ "$PLATFORM" == "macos" ]]; then
CONFIGS=(
"$HOME/.config/kitty|$KITTY_CONFIG"
"$HOME/.config/starship.toml|$STARSHIP_CONFIG"
"$HOME/.config/nvim|$NVIM_CONFIG"
"$HOME/.zshrc|$ZSH_RC"
)
else
CONFIGS=(
"$HOME/.config/kitty|$KITTY_CONFIG"
"$HOME/.config/starship.toml|$STARSHIP_CONFIG"
"$HOME/.config/nvim|$NVIM_CONFIG"
"$HOME/.bashrc|$BASH_RC"
)
fi
# =========================
# SECTION: LINK FUNCTIONS
# =========================
link_windows_config() {
local target="$1"
local source="$2"
local win_target=$(cygpath -w "$target" 2>/dev/null || echo "$target")
local win_source=$(cygpath -w "$source" 2>/dev/null || echo "$source")
if [[ -d "$source" ]]; then
cmd //c "mklink /J $win_target $win_source" >/dev/null 2>&1 &&
log_info "✓ Linked (junction): $target" ||
log_error "Failed to create junction"
else
cmd //c "mklink /H $win_target $win_source" >/dev/null 2>&1 &&
log_info "✓ Linked (hardlink): $target" ||
log_error "Failed to create hardlink"
fi
}
link_config() {
local target="$1"
local source="$2"
mkdir -p "$(dirname "$target")"
if [[ -e "$target" ]]; then
if [[ "$target" == *.bashrc || "$target" == *.zshrc ]]; then
mv "$target" "$target.local"
log_warn "Existing $target will be sourced from $target.local"
else
log_warn "Removing existing target: $target"
rm -rf "$target"
fi
fi
if [[ "$PLATFORM" == "windows" ]]; then
link_windows_config "$target" "$source"
else
ln -sf "$source" "$target" &&
log_info "✓ Linked (symlink): $target" ||
log_error "Failed to create symlink"
fi
}
# =========================
# SECTION: MAIN INSTALL LOOP
# =========================
for mapping in "${CONFIGS[@]}"; do
IFS='|' read -r target source <<<"$mapping"
log_info "Installing config: $target"
if [[ ! -e "$source" ]]; then
log_error "Source not found: $source"
continue
fi
link_config "$target" "$source"
echo
done
log_info "Installation complete!"