dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit afaa6691563c7df2262eb5ee78e856db5f33bc3e (patch)
parent 727c4ddd0e6a26d38da6abed2a36991c7fb03913
Author: Alexander Karle <akarle@umass.edu>
Date:   Sun, 18 Nov 2018 12:21:50 -0500

[bin] clean up install script, create linking script

I found that there was a definite use case where I wanted to
do the linking without running any of the install stuff.

I decided to pull out the shared functions and create a linking
script and an install script. Modularization is nice because I'll
use the messages script if/when I get around to writing an uninstall
script.

Diffstat:
MDockerfile | 2+-
Abin/install.sh | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/link.sh | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/messages.sh | 39+++++++++++++++++++++++++++++++++++++++
Dinstall.sh | 176-------------------------------------------------------------------------------
Dubuntu_setup.sh | 15---------------
6 files changed, 206 insertions(+), 192 deletions(-)

diff --git a/Dockerfile b/Dockerfile @@ -13,7 +13,7 @@ USER akarle # copy in install script! WORKDIR /home/akarle -COPY install.sh ./install.sh +COPY ./bin/install.sh ./install.sh # Start bash on enter CMD ["/bin/bash"] diff --git a/bin/install.sh b/bin/install.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# This script sets up all dotfiles from scratch +# PREREQS: git +# +# NOTE: will not overwrite anything that already exists +# other than .akarledots (which will get backed up) +# +# If you want to just do symlinking, see ./link.sh + +# Before anything, require git to be installed +if ! [ -x "$(command -v git)" ]; then + echo "Error: git is not installed. Aborting..." >&2 + exit 1 +fi + +# Establish Globals +HOMEDOTS=$HOME/.akarledots +DOTVIM=$HOME/.vim + +# Load messages colors + functions +source $HOMEDOTS/bin/messages.sh + +install_via_curl() { + echo "Would you like to install $1 (via curl)" + select opt in "Yes" "No"; do + case $opt in + "Yes" ) + curl -fLo "$3" --create-dirs "$2" + break + ;; + "No" ) + echo "Not installing $1" + break + ;; + esac + done + echo "" + echo "" +} + +# First, backup old copies +if [ -d $HOMEDOTS ]; then + BACKUP="${HOMEDOTS}_backup_$(date +%s)" + mv $HOMEDOTS $BACKUP + warn_msg "Backing up old $HOMEDOTS to $BACKUP" +fi + +# Next, clone a fresh one +git clone https://github.com/akarle/dotfiles.git $HOMEDOTS +success_msg "Clone successful! Putting you on your own branch '$(whoami)' so you can make changes!" +(cd $HOMEDOTS && exec git checkout -b $(whoami)) + +# Do linking +success_msg "Linking..." +source $HOMEDOTS/bin/link.sh + +# Now for Vim +if [ -d $DOTVIM ]; then + BACKUP="${DOTVIM}_backup_$(date +%s)" + mv $DOTVIM $BACKUP + warn_msg "Backing up old $DOTVIM to $BACKUP" +fi + +git clone https://github.com/akarle/dotvim.git $DOTVIM +success_msg "Successfully cloned dotvim to $DOTVIM. Woot!" + +printf "\n\n" + +# Optional installs via curl: +if [ -x "$(command -v curl)" ]; then + # vim-plug + install_via_curl \ + "vim-pathogen" \ + "https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim" \ + "$HOME/.vim/autoload/pathogen.vim" + + # git bash/zsh completion + install_via_curl \ + "bash completion" \ + "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" \ + "$HOME/.bash/git-completion.bash" +fi + +# Logo a la oh-my-zsh (for funsies) +printf ${MAGENTA} +echo "" +echo "Thank you for installing..." +printf ${BOLD}${BLUE} +echo " _ _ _ _ " +echo " | | | | | | | | " +echo " __ _| | ____ _ _ __| | ___ __| | ___ | |_ ___ " +echo " / _ | |/ / _ | '__| |/ _ \/ _ |/ _ \| __/ __| " +echo "${MAGENTA} _${BLUE} | (_| | ( (_| | | | | __/ (_| | (_) | |_\__ \ " +echo "${MAGENTA}(_)${BLUE} \__,_|_|\_\__,_|_| |_|\___|\__,_|\___/ \__|___/ " +printf ${RESET} +echo "" + +# source bash +source ~/.bashrc diff --git a/bin/link.sh b/bin/link.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# link.sh +# Handles all (re)linking of dotfiles to their appropriate place + +# Establish Globals +HOMEDOTS=$HOME/.akarledots +DOTVIM=$HOME/.vim +CONFDIR=$HOME/.config + +# Load messages colors + functions +source $HOMEDOTS/bin/messages.sh + +try_ln() { + # if it doesn't exist, just create it -- works for broken symlinks too! + if [ ! -f $2 ]; then + success_msg "Creating soft symlink from $1 to $2" + ln -s $1 $2 + # if its a symlink replace it + elif [ -L $2 ]; then + warn_msg "$2 is a symlink already, replacing it with a symlink to $1" + rm $2 + ln -s $1 $2 + # if it exists but is not a symlink + else + error_msg "$2 exists as a file that is NOT a symlink. What would you like to do?" + OPT1="Move it to $HOMEDOTS for further inspection and add akarledots link in its place" + OPT2="Delete and replace it with akarledots link" + OPT3="Keep it and do not create akarledots link" + select opt in "$OPT1" "$OPT2" "$OPT3"; do + case $opt in + $OPT1 ) + TMPFILE=$2.BACKUP + mv $2 $TMPFILE + mv $TMPFILE $HOMEDOTS/ + ln -s $1 $2 + break + ;; + $OPT2 ) + rm $2 + ln -s $1 $2 + break + ;; + $OPT3 ) + echo "Not altering $2" + break + ;; + esac + done + fi +} + +# $HOME level ln's +try_ln $HOMEDOTS/tmux.conf $HOME/.tmux.conf +try_ln $HOMEDOTS/zsh/zshrc $HOME/.zshrc +try_ln $HOMEDOTS/inputrc $HOME/.inputrc +try_ln $HOMEDOTS/screenrc $HOME/.screenrc + +# .config lns +try_ln $HOMEDOTS/alacritty.yml $CONFDIR/alacritty/alacritty.yml +try_ln $HOMEDOTS/neovim/init.vim $CONFDIR/nvim/init.vim + +# bash lns +for file in $HOMEDOTS/bash/*; do + [ -e "$file" ] || continue + try_ln $file $HOME/.$(basename $file) +done +unset file diff --git a/bin/messages.sh b/bin/messages.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# messages.sh +# Code to setup variables for pretty and colorful messages + +# Define colors (for printouts) +if tput setaf 1 &> /dev/null; then tput sgr0 + BOLD="$(tput bold)" + MAGENTA="$(tput setaf 5)" + GREEN="$(tput setaf 2)" + RED="$(tput setaf 1)" + RESET="$(tput sgr0)" + if [[ $(tput colors) -ge 16 ]] 2>/dev/null; then + BLUE="$(tput setaf 12)" + ORANGE="$(tput setaf 11)" + else + BLUE="$(tput setaf 4)" + ORANGE="$(tput setaf 3)" + fi +else + BLUE="" + BOLD="" + ORANGE="" + RED="" + GREEN="" + RESET="" +fi + +# Helper functions +success_msg() { + echo "${GREEN}$1${RESET}" +} + +warn_msg() { + echo "${ORANGE}$1${RESET}" +} + +error_msg() { + echo "${RED}$1${RESET}" +} diff --git a/install.sh b/install.sh @@ -1,176 +0,0 @@ -#!/bin/bash -# This script sets up the dotfiles -# PREREQS: git -# NOTE: will not overwrite anything that already exists -# other than .akarledots (which will get backed up) - -# Before anything, require git to be installed -if ! [ -x "$(command -v git)" ]; then - echo "Error: git is not installed. Aborting..." >&2 - exit 1 -fi - -# Establish Globals -HOMEDOTS=$HOME/.akarledots -DOTVIM=$HOME/.vim - -# Define colors (for printouts) -if tput setaf 1 &> /dev/null; then tput sgr0 - BOLD="$(tput bold)" - MAGENTA="$(tput setaf 5)" - GREEN="$(tput setaf 2)" - RED="$(tput setaf 1)" - RESET="$(tput sgr0)" - if [[ $(tput colors) -ge 16 ]] 2>/dev/null; then - BLUE="$(tput setaf 12)" - ORANGE="$(tput setaf 11)" - else - BLUE="$(tput setaf 4)" - ORANGE="$(tput setaf 3)" - fi -else - BLUE="" - BOLD="" - ORANGE="" - RED="" - GREEN="" - RESET="" -fi - - -# Helper functions -success_msg() { - echo "${GREEN}$1${RESET}" -} - -warn_msg() { - echo "${ORANGE}$1${RESET}" -} - -error_msg() { - echo "${RED}$1${RESET}" -} - -try_ln() { - # if it doesn't exist, just create it -- works for broken symlinks too! - if [ ! -f $2 ]; then - success_msg "Creating soft symlink from $1 to $2" - ln -s $1 $2 - # if its a symlink replace it - elif [ -L $2 ]; then - warn_msg "$2 is a symlink already, replacing it with a symlink to $1" - rm $2 - ln -s $1 $2 - # if it exists but is not a symlink - else - error_msg "$2 exists as a file that is NOT a symlink. What would you like to do?" - OPT1="Move it to $HOMEDOTS for further inspection and add akarledots link in its place" - OPT2="Delete and replace it with akarledots link" - OPT3="Keep it and do not create akarledots link" - select opt in "$OPT1" "$OPT2" "$OPT3"; do - case $opt in - $OPT1 ) - TMPFILE=$2.BACKUP - mv $2 $TMPFILE - mv $TMPFILE $HOMEDOTS/ - ln -s $1 $2 - break - ;; - $OPT2 ) - rm $2 - ln -s $1 $2 - break - ;; - $OPT3 ) - echo "Not altering $2" - break - ;; - esac - done - fi -} - -install_via_curl() { - echo "Would you like to install $1 (via curl)" - select opt in "Yes" "No"; do - case $opt in - "Yes" ) - curl -fLo "$3" --create-dirs "$2" - break - ;; - "No" ) - echo "Not installing $1" - break - ;; - esac - done - echo "" - echo "" -} - -# First, backup old copies -if [ -d $HOMEDOTS ]; then - BACKUP="${HOMEDOTS}_backup_$(date +%s)" - mv $HOMEDOTS $BACKUP - warn_msg "Backing up old $HOMEDOTS to $BACKUP" -fi - -# Next, clone a fresh one -git clone https://github.com/akarle/dotfiles.git $HOMEDOTS -success_msg "Clone successful! Putting you on your own branch '$(whoami)' so you can make changes!" -(cd $HOMEDOTS && exec git checkout -b $(whoami)) - -# $HOME level ln's -try_ln $HOMEDOTS/tmux.conf $HOME/.tmux.conf -try_ln $HOMEDOTS/zsh/zshrc $HOME/.zshrc -try_ln $HOMEDOTS/inputrc $HOME/.inputrc - -# Now for Vim -if [ -d $DOTVIM ]; then - BACKUP="${DOTVIM}_backup_$(date +%s)" - mv $DOTVIM $BACKUP - warn_msg "Backing up old $DOTVIM to $BACKUP" -fi - -git clone https://github.com/akarle/dotvim.git $DOTVIM -success_msg "Successfully cloned dotvim to $DOTVIM. Woot!" - -for file in $HOMEDOTS/bash/*; do - [ -e "$file" ] || continue - try_ln $file $HOME/.$(basename $file) -done -unset file - -printf "\n\n" - -# Optional installs via curl: -if [ -x "$(command -v curl)" ]; then - # vim-plug - install_via_curl \ - "vim-pathogen" \ - "https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim" \ - "$HOME/.vim/autoload/pathogen.vim" - - # git bash/zsh completion - install_via_curl \ - "bash completion" \ - "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash" \ - "$HOME/.bash/git-completion.bash" -fi - -# Logo a la oh-my-zsh (for funsies) -printf ${MAGENTA} -echo "" -echo "Thank you for installing..." -printf ${BOLD}${BLUE} -echo " _ _ _ _ " -echo " | | | | | | | | " -echo " __ _| | ____ _ _ __| | ___ __| | ___ | |_ ___ " -echo " / _ | |/ / _ | '__| |/ _ \/ _ |/ _ \| __/ __| " -echo "${MAGENTA} _${BLUE} | (_| | ( (_| | | | | __/ (_| | (_) | |_\__ \ " -echo "${MAGENTA}(_)${BLUE} \__,_|_|\_\__,_|_| |_|\___|\__,_|\___/ \__|___/ " -printf ${RESET} -echo "" - -# source bash -source ~/.bashrc diff --git a/ubuntu_setup.sh b/ubuntu_setup.sh @@ -1,15 +0,0 @@ -#! /bin/bash - -# install vim, tmux, zsh -sudo apt-get -y update -sudo apt-get -y upgrade -sudo apt-get -y install vim -sudo apt-get -y install zsh -sudo apt-get -y install tmux - -# zsh setup! -# oh-my-zsh -sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" - -# zsh-syntax-highlighting -git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting