-
-
Save nipunravisara/985a01f9dc7fe3c5d780e99c4592d7dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
red=`tput setaf 1` | |
green=`tput setaf 2` | |
blue=`tput setaf 6` | |
reset=`tput sgr0` | |
# Function to check if Homebrew is installed and install it if not | |
check_and_install_brew() { | |
if command -v brew >/dev/null 2>&1; then | |
echo "$green ✔ Homebrew is already installed. $green" | |
else | |
echo "$blue Homebrew is not installed. Installing... $blue" | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
echo "export PATH=/opt/homebrew/bin:\$PATH" >> ~/.zprofile | |
export PATH=/opt/homebrew/bin:$PATH | |
if command -v brew >/dev/null 2>&1; then | |
echo "$green ✔ Homebrew has been successfully installed. $green" | |
else | |
echo "$red Failed to install Homebrew. $red" | |
fi | |
fi | |
} | |
# Function to check if Oh My Zsh is installed and install it if not | |
check_and_install_oh_my_zsh() { | |
if [ -d "$HOME/.oh-my-zsh" ]; then | |
echo "$green ✔ Oh My Zsh is already installed. $reset" | |
else | |
echo "$blue Oh My Zsh is not installed. Installing... $reset" | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended" | |
if [ -d "$HOME/.oh-my-zsh" ]; then | |
echo "$green ✔ Oh My Zsh has been successfully installed. $reset" | |
else | |
echo "$red Failed to install Oh My Zsh. $reset" | |
fi | |
fi | |
} | |
# Function to check if an app is installed and install it using brew if not | |
check_and_install_app() { | |
local app_name=$1 | |
local app_code_name=$2 | |
local formula=$3 | |
local brew_cellar="/opt/homebrew/Cellar" | |
local brew_bin="/opt/homebrew/bin" | |
local applications_folder="/Applications" | |
# Check if the package exists in the Cellar directory | |
if [ -d "$brew_cellar/$app_name" ] || [ -x "$brew_bin/$app_name" ] || [ -d "$HOME/.$app_name" ]; then | |
echo "$green ✔ 1 $app_name is already installed. $reset" | |
elif brew list --cask | grep -q "^$app_name\$" || brew list --formula | grep -q "^$app_name\$"; then | |
echo "$green ✔ 2 $app_name is already installed. $reset" | |
else | |
echo "$blue $app_name is not installed. Installing... $reset" | |
if [ -z "$formula" ]; then | |
brew install "$app_name" | |
else | |
brew install "$formula" | |
fi | |
# Re-check after installation | |
if [ -d "$brew_cellar/$app_name" ]; then | |
echo "$green ✔ $app_name has been successfully installed. $reset" | |
elif brew list --cask | grep -q "^$app_name\$" || brew list --formula | grep -q "^$app_name\$"; then | |
echo "$green ✔ $app_name has been successfully installed. $reset" | |
else | |
echo "$red Failed to install $app_name. $reset" | |
fi | |
fi | |
} | |
# Setup dotfiles from git | |
setup_dotfiles() { | |
if [ -d "$HOME/.dotfiles" ]; then | |
echo "$green ✔ Dotfiles are already configured. $reset" | |
else | |
echo "$blue Cleaning old dotfiles $reset" | |
echo "$blue Setting up dotfiles $reset" | |
echo ".dotfiles" >> .gitignore | |
git clone --bare https://github.com/nipunravisara/dotfiles $HOME/.dotfiles | |
rm -rf ~/.config | |
echo "$blue ~/.config removed $reset" | |
rm -rf ~/.local | |
echo "$blue ~/.local removed $reset" | |
rm -rf ~/.zshrc | |
echo "$blue ~/.zshrc removed $reset" | |
rm -rf ~/.gitconfig | |
echo "$blue ~/.gitconfig removed $reset" | |
rm -rf ~/.zprofile | |
echo "$blue ~/.zprofile removed $reset" | |
rm -rf ~/.gitignore | |
echo "$blue ~/.gitignore removed $reset" | |
rm -rf ~/README.md | |
echo "$blue ~/README.md removed $reset" | |
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME checkout | |
/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME config --local status.showUntrackedFiles no | |
ln -s .config/zsh/zshrc ~/.zshrc | |
ln -s .config/zsh/zprofile ~/.zprofile | |
ln -s .config/git/gitconfig ~/.gitconfig | |
echo "$green ✔ Dotfiles configured. $reset" | |
fi | |
} | |
# Download choise of font | |
check_and_download_fonts() { | |
fonts=( | |
"JetBrainsMonoNerdFontMono-Regular.ttf https://github.com/ryanoasis/nerd-fonts/raw/HEAD/patched-fonts/JetBrainsMono/Ligatures/Regular/JetBrainsMonoNerdFontMono-Regular.ttf" | |
"JetBrainsMonoNerdFontMono-Italic.ttf https://github.com/ryanoasis/nerd-fonts/raw/HEAD/patched-fonts/JetBrainsMono/Ligatures/Italic/JetBrainsMonoNerdFontMono-Italic.ttf" | |
"JetBrainsMonoNerdFontMono-Bold.ttf https://github.com/ryanoasis/nerd-fonts/raw/HEAD/patched-fonts/JetBrainsMono/Ligatures/Bold/JetBrainsMonoNerdFontMono-Bold.ttf" | |
) | |
all_fonts_available=true | |
for font_data in "${fonts[@]}"; do | |
font=(${font_data}) # Split the string into an array | |
font_name=${font[0]} | |
font_url=${font[1]} | |
if [ ! -e "$HOME/Library/Fonts/$font_name" ]; then | |
all_fonts_available=false | |
break | |
fi | |
done | |
if $all_fonts_available; then | |
echo "$green ✔ All fonts are already available. $reset" | |
else | |
for font_data in "${fonts[@]}"; do | |
font=(${font_data}) # Split the string into an array | |
font_name=${font[0]} | |
font_url=${font[1]} | |
if [ ! -e "$HOME/Library/Fonts/$font_name" ]; then | |
echo "$blue Downloading $font_name... $reset" | |
curl -fLo "$HOME/Library/Fonts/$font_name" "$font_url" | |
fi | |
done | |
fi | |
} | |
# Install plugins and start services | |
post_installation_setup() { | |
if [ -d ~/.tmux/plugins/tpm ]; then | |
echo "$green ✔ Tmux plugin manager is already installed. $reset" | |
else | |
echo "$blue TPM is not installed, Installing tmux plugin manager... $reset" | |
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm | |
fi | |
skhd --install-service | |
skhd --start-service | |
yabai --install-service | |
yabai --start-service | |
} | |
check_and_install_brew "brew" "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
echo "export PATH=/opt/homebrew/bin:$PATH" >> .zprofile | |
check_and_install_oh_my_zsh | |
check_and_install_app "nvm" | |
check_and_install_app "alacritty" | |
check_and_install_app "ripgrep" | |
check_and_install_app "visual-studio-code" "Visual Studio Code" | |
check_and_install_app "google-chrome" "Google Chrome" | |
check_and_install_app "firefox" | |
check_and_install_app "tmux" | |
check_and_install_app "skhd" "skhd" "koekeishiya/formulae/skhd" | |
check_and_install_app "yabai" "yabai" "koekeishiya/formulae/yabai" | |
check_and_download_fonts | |
setup_dotfiles | |
post_installation_setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment