-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·327 lines (280 loc) · 9.97 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·327 lines (280 loc) · 9.97 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
#!/bin/bash
#
# dotfiles setup script
# KH
#
DOTS_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Parse command line arguments
HEADLESS=false
UBUNTU=false
MACOS=false
while [[ $# -gt 0 ]]; do
case $1 in
--headless)
HEADLESS=true
shift
;;
--ubuntu|-u)
UBUNTU=true
shift
;;
--macos|-m)
MACOS=true
shift
;;
--help)
echo "Usage: $0 [OPTIONS]"
echo "Options:"
echo " --headless Install only non-graphical components"
echo " -u, --ubuntu Configure for Ubuntu (default: Arch Linux)"
echo " -m, --macos Configure for macOS with Homebrew"
echo " --help Show this help message"
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# macOS has no Wayland/X11, so skip graphical configs
if [[ "$MACOS" == "true" ]]; then
HEADLESS=true
fi
echo "Installing dotfiles relative to: $DOTS_HOME..."
echo "Headless mode: $HEADLESS"
echo "Ubuntu mode: $UBUNTU"
echo "macOS mode: $MACOS"
# Define package lists based on distribution
if [[ "$MACOS" == "true" ]]; then
PACKAGES=("bat" "coreutils" "dust" "fd" "figlet" "fzf" "gotop"
"lolcat" "lsd" "neovim" "ripgrep" "thefuck" "tldr"
"tmux" "tre-command" "visidata" "zoxide")
FONT_PACKAGES=("font-hack-nerd-font" "font-symbols-only-nerd-font")
PACKAGE_MANAGER="brew"
PACKAGE_INSTALL_CMD="brew install"
PACKAGE_UPDATE_CMD="brew update"
elif [[ "$UBUNTU" == "true" ]]; then
PACKAGES=("bat" "fd-find" "fzf" "lsd" "ripgrep" "thefuck" "tldr" "visidata" "zoxide")
FONT_PACKAGES=("fonts-nerd-fonts" "fonts-weather-icons")
PACKAGE_MANAGER="apt"
PACKAGE_INSTALL_CMD="sudo apt install -y"
PACKAGE_UPDATE_CMD="sudo apt update"
else
PACKAGES=("bat" "dust" "fd" "fzf" "gotop-bin" "lolcat" "lsd" "moor" "ripgrep" "tre-command" "thefuck" "tldr" "visidata" "xan" "zoxide")
FONT_PACKAGES=("ttf-nerd-fonts-symbols" "ttf-hack-nerd" "ttf-weather-icons")
PACKAGE_MANAGER="yay"
PACKAGE_INSTALL_CMD="yay -S"
PACKAGE_UPDATE_CMD=""
fi
# Define configuration components
GRAPHICAL_CONFIGS=("feh" "hypr" "niri" "zathura")
COMMON_CONFIGS=("fcitx" "git" "kitty" "mimeapps.list" "nvim" "lsd" "snakemake" "termcolors" "yazi")
if [[ "$MACOS" == "true" ]]; then
# Remove Linux-only configs
_filtered=()
for item in "${COMMON_CONFIGS[@]}"; do
[[ "$item" != "fcitx" && "$item" != "mimeapps.list" ]] && _filtered+=("$item")
done
COMMON_CONFIGS=("${_filtered[@]}")
unset _filtered
fi
COMMON_DOTFILES=("condarc" "ctags" "plotly" "Rprofile" "Renviron" "tmux.conf" "visidatarc")
# Check for configuration directory
if [ -z $XDG_CONFIG_HOME ]; then
XDG_CONFIG_HOME=$HOME/.config
fi
mkdir -p $XDG_CONFIG_HOME
# Create completions cache dir
mkdir -p $HOME/.cache/zinit/completions
# Install zinit outside shell startup.
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
if [[ ! -d "$ZINIT_HOME/.git" ]]; then
mkdir -p "$(dirname "$ZINIT_HOME")"
git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
# Checks for file or directory and creates a sym link if it doesn't already exist
function ln_s() {
# Existing symlinks are replaced; a real file/dir is moved aside to .bak so
# we never nest a link inside it (e.g. an app-generated ~/.config/kitty) or
# clobber real data.
if [[ -L "$2" ]]; then
rm "$2"
elif [[ -e "$2" ]]; then
echo "[BACKUP] \"$2\" -> \"$2.bak\""
mv "$2" "$2.bak"
fi
echo "[CREATING] \"$2\""
ln -sf $1 $2
}
# Function to install packages
function install_packages() {
local packages=("$@")
local distro_name
if [[ "$MACOS" == "true" ]]; then
distro_name="macOS (Homebrew)"
elif [[ "$UBUNTU" == "true" ]]; then
distro_name="Ubuntu"
else
distro_name="Arch"
fi
echo "$distro_name packages:"
printf '%s ' "${packages[@]}"
echo ""
printf '%s ' "${FONT_PACKAGES[@]}"
echo ""
while true; do
read -r -p "Install $distro_name packages? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
if [[ "$MACOS" == "true" ]]; then
echo "Installing macOS packages via Homebrew..."
brew update
brew install "${packages[@]}"
brew install --cask "${FONT_PACKAGES[@]}"
elif [[ "$UBUNTU" == "true" ]]; then
echo "Installing Ubuntu packages..."
$PACKAGE_UPDATE_CMD
$PACKAGE_INSTALL_CMD "${packages[@]}"
$PACKAGE_INSTALL_CMD "${FONT_PACKAGES[@]}"
else
echo "Installing yay AUR helper..."
cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
cd -
echo "Finished installing yay..."
echo "Installing Arch packages..."
$PACKAGE_INSTALL_CMD "${packages[@]}"
$PACKAGE_INSTALL_CMD "${FONT_PACKAGES[@]}"
fi
break
;;
[nN][oO]|[nN])
echo "Skipping $distro_name package installation..."
break
;;
*)
echo "Invalid input..."
;;
esac
done
}
echo "Setting up dotfiles..."
# Setup zsh
ln_s ${DOTS_HOME}/zshrc ~/.zshrc
ln_s ${DOTS_HOME}/zshenv ~/.zshenv
ln_s ${DOTS_HOME}/shell ~/.shell
# Create needed directories (only for graphical mode)
if [[ "$HEADLESS" == "false" ]]; then
# Gtk 3.0
if [ ! -e ${XDG_CONFIG_HOME}/gtk-3.0/ ]; then
mkdir ${XDG_CONFIG_HOME}/gtk-3.0/
fi
ln_s ${DOTS_HOME}/gtk-3.0/settings.ini ${XDG_CONFIG_HOME}/gtk-3.0/settings.ini
ln_s ${DOTS_HOME}/gtk-3.0/gtk.css ${XDG_CONFIG_HOME}/gtk-3.0/gtk.css
# Gtk 4.0
if [ ! -e ${XDG_CONFIG_HOME}/gtk-4.0/ ]; then
mkdir ${XDG_CONFIG_HOME}/gtk-4.0/
fi
ln_s ${DOTS_HOME}/gtk-4.0/settings.ini ${XDG_CONFIG_HOME}/gtk-4.0/settings.ini
ln_s ${DOTS_HOME}/gtk-4.0/gtk.css ${XDG_CONFIG_HOME}/gtk-4.0/gtk.css
fi
# Install ~/.config components
if [[ "$HEADLESS" == "false" ]]; then
for path in "${GRAPHICAL_CONFIGS[@]}"; do
if [[ "$path" == "niri" && -e "${XDG_CONFIG_HOME}/${path}" && ! -L "${XDG_CONFIG_HOME}/${path}" ]]; then
if [ -e "${XDG_CONFIG_HOME}/${path}.bak" ]; then
echo "Refusing to overwrite existing ${XDG_CONFIG_HOME}/${path}.bak"
exit 1
fi
mv "${XDG_CONFIG_HOME}/${path}" "${XDG_CONFIG_HOME}/${path}.bak"
fi
ln_s ${DOTS_HOME}/${path} ${XDG_CONFIG_HOME}/${path}
done
if [ -x "${XDG_CONFIG_HOME}/niri/host_specific.sh" ]; then
"${XDG_CONFIG_HOME}/niri/host_specific.sh"
fi
fi
for path in "${COMMON_CONFIGS[@]}"; do
ln_s ${DOTS_HOME}/${path} ${XDG_CONFIG_HOME}/${path}
done
# kitty OS-specific overrides (pulled in via `include os-local.conf`)
if [[ "$MACOS" == "true" ]]; then
ln_s ${DOTS_HOME}/kitty/os-macos.conf ${DOTS_HOME}/kitty/os-local.conf
# macOS ships no xterm-kitty in its terminfo db, so git/less/etc. warn the
# "terminal is not fully functional". Compile kitty's bundled entry into
# ~/.terminfo, which ncurses auto-searches. (Linux gets it from the
# kitty-terminfo package.)
_kitty_terminfo="/Applications/kitty.app/Contents/Resources/kitty/terminfo/kitty.terminfo"
[[ -f "$_kitty_terminfo" ]] && tic -x -o ~/.terminfo "$_kitty_terminfo"
unset _kitty_terminfo
else
ln_s ${DOTS_HOME}/kitty/os-linux.conf ${DOTS_HOME}/kitty/os-local.conf
fi
# Install ~/. components
for path in "${COMMON_DOTFILES[@]}"; do
ln_s ${DOTS_HOME}/${path} ~/.${path}
done
# ghci
mkdir -p ${HOME}/.ghc
ln_s ${DOTS_HOME}/ghci.conf ${HOME}/.ghc/ghci.conf
# gimp (only for graphical mode)
if [[ "$HEADLESS" == "false" ]]; then
GIMP_DIR="${XDG_CONFIG_HOME}/GIMP/3.0"
GIMP_PLUGIN_DIR="${XDG_CONFIG_HOME}/GIMP/3.0/plug-ins"
GIMPRC="${GIMP_DIR}/gimprc"
mkdir -p "${GIMP_DIR}"
if [ -e $GIMPRC ]; then
mv $GIMPRC $GIMPRC.bak
fi
if [ -e $GIMP_PLUGIN_DIR ]; then
mv $GIMP_PLUGIN_DIR $GIMP_PLUGIN_DIR.bak
fi
ln -s "${DOTS_HOME}/gimp/gimprc" $GIMPRC
ln -s "${DOTS_HOME}/gimp/plug-ins" $GIMP_PLUGIN_DIR
fi
# noctalia plugin (only for graphical mode)
if [[ "$HEADLESS" == "false" ]]; then
NOCTALIA_PLUGIN_DIR="${XDG_CONFIG_HOME}/noctalia/plugins"
WALI_PANEL_PLUGIN="${NOCTALIA_PLUGIN_DIR}/wali-panel"
mkdir -p "${NOCTALIA_PLUGIN_DIR}"
if [ -e "${WALI_PANEL_PLUGIN}" ] && [ ! -L "${WALI_PANEL_PLUGIN}" ]; then
mv "${WALI_PANEL_PLUGIN}" "${WALI_PANEL_PLUGIN}.bak"
fi
ln_s "${DOTS_HOME}/noctalia/plugins/wali-panel" "${WALI_PANEL_PLUGIN}"
fi
# git
ln_s ${DOTS_HOME}/git/ignore ${HOME}/.gitignore_global
ln_s ${DOTS_HOME}/git/config ${HOME}/.gitconfig
# julia
mkdir -p ${HOME}/.julia/config
ln_s ${DOTS_HOME}/julia/startup.jl ${HOME}/.julia/config/startup.jl
# jupyter
mkdir -p ${HOME}/.jupyter
ln_s ${DOTS_HOME}/jupyter/jupyter_qtconsole_config.py ${HOME}/.jupyter/jupyter_qtconsole_config.py
# mamba
ln_s ${DOTS_HOME}/condarc ${HOME}/.mambarc
# r
ln_s ${DOTS_HOME}/lintr ${HOME}/.lintr
# ripgrep
ln_s ${DOTS_HOME}/rgignore ${HOME}/.rgignore
# scripts, etc.
ln_s ${DOTS_HOME}/bin ${HOME}/bin
# mimetypes (Linux only)
if [[ "$MACOS" != "true" ]]; then
mkdir -p ~/.local/share/mime
ln_s ${DOTS_HOME}/mime ~/.local/share/mime/packages
update-mime-database ~/.local/share/mime
rm ${XDG_CONFIG_HOME}/mimeapps.list
ln_s ${DOTS_HOME}/mimeapps.list ${XDG_CONFIG_HOME}/mimeapps.list
fi
# install tpm
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
#
# external dependencies
#
install_packages "${PACKAGES[@]}"
echo "Done!"