-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
Β·133 lines (107 loc) Β· 3.77 KB
/
build
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
#!/bin/bash
##############################################
# COLOR #
##############################################
RED=$(tput setaf 1)
BLUE=$(tput setaf 4)
RESET=$(tput sgr0)
##############################################
# FUNCTIONS #
##############################################
DOTFILES_PATH="$HOME/.dotfiles"
check_dotfiles_path() {
if [ ! -d "$DOTFILES_PATH" ]; then
if [ -e "$DOTFILES_PATH" ]; then
confirm "Directory $DOTFILES_PATH already exists. Do you want to delete it?" && rm -rf "$DOTFILES_PATH"
if [ -e "$DOTFILES_PATH" ]; then
handle_error "Failed to delete existing directory $DOTFILES_PATH."
fi
echo "${RED}Thanks for using build script! π C'ya next time${RESET}"
exit 0
fi
echo "${BLUE}Cloning dotfiles repository...${RESET}"
git clone https://github.com/Mephisto-Grumpy/dotfiles "$DOTFILES_PATH" || handle_error "Failed to clone dotfiles repository."
fi
}
confirm() {
read -r -p "$1 [y/N] " response
case "$response" in
[yY][eE][sS] | [yY])
true
;;
*)
false
;;
esac
}
handle_error() {
echo "${RED}Error: $1${RESET}" >&2
exit 1
}
install_homebrew() {
echo "${BLUE}Installing πΊ Homebrew...${RESET}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" || handle_error "Failed to install Homebrew."
if [[ "$OSTYPE" == "darwin"* ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
}
install_brew_packages() {
echo "${BLUE}Installing πΊ Homebrew packages...${RESET}"
brew bundle --file="$DOTFILES_PATH/Brewfile" || handle_error "Failed to install Homebrew packages."
}
setup_fish_shell() {
echo "${BLUE}Setting up π Fish shell...${RESET}"
if ! command -v fish &>/dev/null; then
handle_error "Fish shell is not installed."
fi
if ! fish -c "fisher --version" >/dev/null; then
fish -c "curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher" || handle_error "Failed to install Fisher."
else
echo "Fisher is already installed."
fi
echo "${BLUE}Setting up π Fish shell as temporary default shell...${RESET}"
echo "$(which fish)" | sudo tee -a /etc/shells
chsh -s "$(which fish)" || handle_error "Failed to set Fish shell as temporary default."
}
restore_default_shell() {
echo "${BLUE}Restoring default shell...${RESET}"
chsh -s "$(getent passwd "$USER" | cut -d: -f7)" || handle_error "Failed to restore default shell."
}
install_fish_packages() {
echo "${BLUE}Installing π Fish shell packages...${RESET}"
fish -c "fisher install jethrokuan/z" || handle_error "Failed to install z."
fish -c "fisher install PatrickF1/fzf.fish" || handle_error "Failed to install fzf."
fish -c "fisher install nickeb96/puffer-fish" || handle_error "Failed to install puffer-fish."
fish -c "fisher install laughedelic/pisces" || handle_error "Failed to install pisces."
}
link_dotfiles() {
echo "${BLUE}Linking dotfiles...${RESET}"
ln -sf "$DOTFILES_PATH/.gitconfig" "$HOME/.gitconfig"
ln -sf "$DOTFILES_PATH/.gitignore" "$HOME/.gitignore"
ln -sf "$DOTFILES_PATH/.config" "$HOME/.config"
ln -sf "$DOTFILES_PATH/.czrc" "$HOME/.czrc"
}
main() {
echo "${BLUE}Setting up dotfiles...${RESET}"
check_dotfiles_path
confirm "This script will install and configure dotfiles. Continue?" || exit
current_shell=$(basename "$SHELL")
if [[ "$current_shell" == "bash" || "$current_shell" == "zsh" ]]; then
install_homebrew
install_brew_packages
setup_fish_shell
install_fish_packages
restore_default_shell
else
install_homebrew
install_brew_packages
install_fish_packages
fi
link_dotfiles
}
##############################################
# MAIN #
##############################################
main