-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·117 lines (96 loc) · 4.14 KB
/
setup.sh
File metadata and controls
executable file
·117 lines (96 loc) · 4.14 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
#!/usr/bin/env bash
echo "Setting up..."
CWD="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Installs a file or directory from a source path to a destination path within the user's home directory.
# This function first removes any existing item at the destination and ensures its parent directories exist.
#
# Arguments:
# $1 (source_path): The path to the source file or directory, relative to the current working directory ($CWD).
# $2 (dest_path): The desired destination path, relative to the user's home directory ($HOME).
# $3 (copy_mode_flag): Optional. If '1', performs a full recursive copy (`cp -Ra`).
# Otherwise (default), creates a symbolic link (`ln -s`).
install() {
echo "Insalling: $@"
rm -rf "$HOME/$2"
mkdir -p "$(dirname "$HOME/$2")"
if ! [[ "$3" -eq 1 ]]; then
ln -s "$CWD/$1" "$HOME/$2"
else
cp -Ra "$CWD/$1" "$HOME/$2"
fi
}
uninstall() {
rm -rf "$HOME/$1"
}
# clone_if_empty <target_dir> <repo_url>
#
# Clones a Git repository into the specified target directory,
# but only if the directory does not exist or is empty.
#
# Arguments:
# target_dir - The directory to clone the repository into.
# repo_url - The URL of the Git repository to clone.
#
clone_if_empty() {
local target_dir="$1"
local repo_url="$2"
if [ ! -d "$target_dir" ] || [ -z "$(ls -A "$target_dir")" ]; then
echo "Cloning into $target_dir..."
git clone --depth=1 "$repo_url" "$target_dir"
else
echo "Directory '$target_dir' exists and is not empty. Skipping clone."
fi
}
###############################################################################
# dotfiles
###############################################################################
declare -a files=(
.bash_profile
.bashrc
.dircolors
.editorconfig
.gitconfig
.zshrc
.dircolors
)
for file in "${files[@]}"; do
if [[ -f $file ]]; then
install "$file" "$file"
fi
done
###############################################################################
# vim, nvim, tmux
###############################################################################
uninstall ".config/nvim"
uninstall ".vim"
uninstall ".vimrc"
uninstall ".tmux.conf"
install "nvim" ".config/nvim" 1
install "vim" ".vim" 1
install ".vimrc" ".vimrc" 1
install "tmux/.tmux.conf" ".tmux.conf" 1
###############################################################################
# wezterm
###############################################################################
uninstall ".config/wezterm"
install "wezterm" ".config/wezterm" 1
###############################################################################
# oh my zsh
###############################################################################
clone_if_empty "$HOME/.oh-my-zsh" "https://github.com/ohmyzsh/ohmyzsh.git"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" "https://github.com/romkatv/powerlevel10k.git"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" "https://github.com/zsh-users/zsh-autosuggestions"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting" "https://github.com/zsh-users/zsh-syntax-highlighting.git"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting" "https://github.com/zdharma-continuum/fast-syntax-highlighting.git"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/k" "https://github.com/supercrabtree/k"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autocomplete" "https://github.com/marlonrichert/zsh-autocomplete.git"
clone_if_empty "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/autojump-setup" "https://github.com/wting/autojump.git"
cd ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/autojump-setup && python3 install.py
###############################################################################
# zinit
###############################################################################
rm -rf "$HOME/.zinit"
mkdir "$HOME/.zinit"
git clone --depth=1 https://github.com/zdharma-continuum/zinit.git "$HOME/.zinit/bin"
echo -e "Installation done for the following ${#files[*]} dotfiles: ${files[*]}"
source $HOME/.zshrc