mirror of
https://github.com/Lissy93/dotfiles.git
synced 2024-11-22 07:23:10 +01:00
Adds PlugInstall, make user input optional, refactor setup into own function
This commit is contained in:
parent
05d971ba24
commit
d80635e3ec
87
install.sh
87
install.sh
@ -7,7 +7,7 @@
|
||||
|
||||
# IMPORTANT: Before running, read through everything, and confirm it's what you want!
|
||||
|
||||
set -e
|
||||
# set -e
|
||||
|
||||
# Configuration Params
|
||||
REPO_NAME="Lissy93/Dotfiles"
|
||||
@ -28,6 +28,9 @@ PLAIN_B='\033[1;37m'
|
||||
RESET='\033[0m'
|
||||
PURPLE='\033[0;35m'
|
||||
|
||||
# Other params
|
||||
PROMPT_TIMEOUT=15 # When user is prompted for input, skip after x seconds
|
||||
|
||||
# Start timer
|
||||
start_time=`date +%s`
|
||||
|
||||
@ -87,15 +90,6 @@ function pre_setup_tasks () {
|
||||
# Downloads / updates dotfiles and symlinks them
|
||||
function setup_dot_files () {
|
||||
|
||||
# If ZSH not the default shell, ask user if they'd like to set it
|
||||
if [[ $SHELL != *"zsh"* ]] && command_exists zsh; then
|
||||
read -p "Would you like to set ZSH as your default shell? (y/N)" -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
chsh -s $(which zsh) $USER
|
||||
fi
|
||||
fi
|
||||
|
||||
# Download / update dotfiles repo with git
|
||||
if [[ ! -d "$DOTFILES_DIR" ]]
|
||||
then
|
||||
@ -104,7 +98,7 @@ function setup_dot_files () {
|
||||
git clone --recursive ${REPO_PATH} ${DOTFILES_DIR}
|
||||
else
|
||||
echo -e "${PURPLE}Pulling changes from ${REPO_NAME} into ${DOTFILES_DIR}"
|
||||
cd "${DOTFILES_DIR}" && git pull && git submodule update --recursive
|
||||
cd "${DOTFILES_DIR}" && git pull origin master && git submodule update --recursive
|
||||
fi
|
||||
|
||||
# If git clone / pull failed, then exit with error
|
||||
@ -123,35 +117,57 @@ function setup_dot_files () {
|
||||
"${DOTFILES_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${DOTFILES_DIR}" -c "${CONFIG}" "${@}"
|
||||
}
|
||||
|
||||
# Applies application-specific preferences, and runs some setup tasks
|
||||
function apply_preferences () {
|
||||
|
||||
# If ZSH not the default shell, ask user if they'd like to set it
|
||||
if [[ $SHELL != *"zsh"* ]] && command_exists zsh; then
|
||||
read -t $PROMPT_TIMEOUT -p "Would you like to set ZSH as your default shell? (y/N)" -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
chsh -s $(which zsh) $USER
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install / update vim plugins with Plug
|
||||
vim +PlugInstall +qall
|
||||
|
||||
# Install / update Tmux plugins with TPM
|
||||
chmod ug+x "${XDG_DATA_HOME}/tmux/tpm"
|
||||
}
|
||||
|
||||
# Based on system type, uses appropriate package manager to install / updates apps
|
||||
function install_packages () {
|
||||
# Mac OS
|
||||
if [ "$system_type" = "Darwin" ]; then
|
||||
# Homebrew not installed, ask user if they'd like to download it now
|
||||
if ! command_exists brew; then
|
||||
read -p "Would you like to install Homebrew? (y/N)" -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo -en "🍺 ${YELLOW_B}Installing Homebrew...${RESET}\n"
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
export PATH=/opt/homebrew/bin:$PATH
|
||||
fi
|
||||
fi
|
||||
# Update / Install the Homebrew packages in ~/.Brewfile
|
||||
if command_exists brew && [ -f "$HOME/.Brewfile" ]
|
||||
then
|
||||
echo -e "${PURPLE}Updating homebrew and packages...${RESET}"
|
||||
brew update
|
||||
brew upgrade
|
||||
BREW_PREFIX=$(brew --prefix)
|
||||
brew bundle --global --file $HOME/.Brewfile
|
||||
brew cleanup
|
||||
|
||||
read -t $PROMPT_TIMEOUT -p "Would you like to install / update system packages? (y/N) " -n 1 -r
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo -e "\n${PURPLE}Skipping package installs${RESET}"
|
||||
return
|
||||
fi
|
||||
|
||||
# Mac OS
|
||||
if [ "$system_type" = "Darwin" ]; then
|
||||
# Homebrew not installed, ask user if they'd like to download it now
|
||||
if ! command_exists brew; then
|
||||
read -t $PROMPT_TIMEOUT -p "Would you like to install Homebrew? (y/N)" -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo -en "🍺 ${YELLOW_B}Installing Homebrew...${RESET}\n"
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
export PATH=/opt/homebrew/bin:$PATH
|
||||
fi
|
||||
fi
|
||||
# Windows (WIP)
|
||||
if [ "$system_type" = "WindowsNT" ] || [ "$OSTYPE" = "msys" ] || [ "$OSTYPE" = "cygwin" ]; then
|
||||
"${DOTFILES_DIR}/installs/windows.sh"
|
||||
# Update / Install the Homebrew packages in ~/.Brewfile
|
||||
if command_exists brew && [ -f "$HOME/.Brewfile" ]
|
||||
then
|
||||
echo -e "${PURPLE}Updating homebrew and packages...${RESET}"
|
||||
brew update
|
||||
brew upgrade
|
||||
BREW_PREFIX=$(brew --prefix)
|
||||
brew bundle --global --file $HOME/.Brewfile
|
||||
brew cleanup
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Updates current session, and outputs summary
|
||||
@ -168,6 +184,7 @@ function finishing_up () {
|
||||
# Begin!
|
||||
pre_setup_tasks # Print start message, and check requirements are met
|
||||
setup_dot_files # Clone / updatae dotfiles, and create the symlinks
|
||||
apply_preferences # Set settings for individual applications
|
||||
install_packages # Prompt to install / update OS-specific packages
|
||||
finishing_up # Re-source .zshenv, and print summary
|
||||
# All done!
|
||||
|
Loading…
Reference in New Issue
Block a user