#!/bin/bash ####################################################################### # Helper functions ####################################################################### # Make a folder (throw errors if it's already there but not a folder) mkfolder() { if [[ -e $1 ]] then if [[ ! -d $1 ]] then echo "$1 is not a directory!" echo "Backing up $1 to $1.bak" mv -v $1 $1.bak mkdir -p $1 fi else mkdir -p $1 fi } # Symlink file to destination folder lnfile() { # See if we are linking to a directory if [[ $2 =~ /$ ]] then FILE_PATH=$2 FILE_NAME=$(basename $1) DST_FILE="${FILE_PATH}${FILE_NAME}" else FILE_PATH=$(dirname $2) FILE_NAME=$(basename $2) DST_FILE="$FILE_PATH/$FILE_NAME" fi SRC_FILE="$DF_PATH/$1" WRITE_LINK=0 # See if the target exists if [[ -e $DST_FILE ]] then # Is the target a symbolic link? if [[ -L $DST_FILE ]] then POINTS_TO=$(readlink $DST_FILE) # Does it point to our file? if [[ "$POINTS_TO" != "$SRC_FILE" ]] then echo "Target $DST_FILE points to a different file - $POINTS_TO" echo -n "Replace link to point to $SRC_FILE? [y/n] " read -n1 echo if [[ $REPLY == y || $REPLY == Y ]] then WRITE_LINK=1 # Remove the old symbolic link rm -f $DST_FILE fi #else # It already points to our file. No point in rewriting it. fi else # No, it's not a symbolic link echo "Target $DST_FILE is not a symbolic link!" echo "Backing up to $DST_FILE.bak" mv -v $DST_FILE ${DST_FILE}.bak WRITE_LINK=1 fi else WRITE_LINK=1 fi if [[ ! -z $DEBUG ]] then echo -n "Linking " [[ ! -z $WRITE_LINK ]] && echo -n "(NOT) " echo "'$DST_FILE' -> '$SRC_FILE'" fi if [[ $WRITE_LINK == 1 ]] then echo "Installing $1" ln -s "$SRC_FILE" "$DST_FILE" fi } # Install/update vim bundles vim_update_bundle() { BUNDLE=$(echo $1 | sed 's:^.*/::' | sed 's:\.git$::') # If the bundle already exists, update it (if possible) if [[ -d "$HOME/.vim/bundle/$BUNDLE" ]] then if [[ -d "$HOME/.vim/bundle/$BUNDLE/.git" ]] then echo "Updating bundle $BUNDLE..." pushd "$HOME/.vim/bundle/$BUNDLE" >/dev/null git pull popd >/dev/null echo else echo "$BUNDLE is not a Git repository. Skipping update." fi else echo "Installing bundle $BUNDLE..." pushd "$HOME/.vim/bundle/" >/dev/null git clone $1 popd >/dev/null echo fi } ####################################################################### # Install dotfiles ####################################################################### # Install scripts/config files to corresponding destination folders cd $(dirname $0) DF_PATH=$(pwd) PRINT_PATH=$(echo $DF_PATH | sed "s:^$HOME:~:") echo Installing dotfiles from $PRINT_PATH ####################################################################### # Install scripts ####################################################################### # Create ~/bin folder mkfolder ~/bin # Install scripts lnfile scripts/beep ~/bin/ lnfile scripts/sdate ~/bin/stardate lnfile scripts/settitle ~/bin/ lnfile scripts/smartwd ~/bin/ # Don't bother installing the note script on a Mac, it doesn't work that well if [[ "$(uname)" != *"Darwin"* ]] then lnfile scripts/note ~/bin/ lnfile scripts/note ~/bin/n fi ####################################################################### # Install git configuration ####################################################################### if [[ ! -e ~/.gitconfig ]] then echo "Installing gitconfig" cp -v gitconfig ~/.gitconfig echo -n "What is your default Git username? " read $GIT_USER echo -n "What is your default Git e-mail address? " read $GIT_EMAIL git config --global user.name $GIT_USER git config --global user.email $GIT_EMAIL fi # Install git prompt functions if [[ ! -e ~/.git_prompt.sh ]] then echo "Installing Git prompt functionality..." curl -Sso ~/.git_prompt.sh \ https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh fi ####################################################################### # Install vimrc & plugins ####################################################################### # Create VIM folders mkfolder ~/.vim mkfolder ~/.vim/autoload mkfolder ~/.vim/bundle mkfolder ~/.vim/colors mkfolder ~/.vim/ftplugin mkfolder ~/.vim/plugin mkfolder ~/.vim/syntax # Install vim files lnfile vimrc ~/.vimrc # Install my plugins lnfile vim/plugin/long-lines.vim ~/.vim/plugin/ lnfile vim/plugin/match-brackets.vim ~/.vim/plugin/ # Install my filetype plugins lnfile vim/ftplugin/make.vim ~/.vim/ftplugin/ lnfile vim/ftplugin/perl.vim ~/.vim/ftplugin/ lnfile vim/ftplugin/ruby.vim ~/.vim/ftplugin/ # Install pathogen if [[ ! -f ~/.vim/autoload/pathogen.vim ]] then echo "Installing vim-pathogen" curl -Sso ~/.vim/autoload/pathogen.vim \ https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim fi ####################################################################### # Install/update Vim bundles ####################################################################### # tmux config file syntax vim_update_bundle https://github.com/zaiste/tmux.vim.git # Solarized vim_update_bundle https://github.com/altercation/vim-colors-solarized.git # Vimwiki vim_update_bundle https://github.com/vim-scripts/vimwiki.git # snipMate vim_update_bundle https://github.com/msanders/snipmate.vim.git ####################################################################### # Install tmux & screen config files ####################################################################### # Install tmux configuration file lnfile tmux.conf ~/.tmux.conf # Install screen configuration file lnfile screenrc ~/.screenrc ####################################################################### # Install bashrc files ####################################################################### if [[ -L ~/.bashrc.common ]] then PRINT_INST=0 else PRINT_INST=1 fi lnfile bash/bashrc.common ~/.bashrc.common lnfile bash/bashrc.lscolors ~/.bashrc.lscolors lnfile dircolors ~/.dir_colors if [[ $PRINT_INST == 1 ]] then echo "Add the following line to your ~/.bashrc file" echo " source ~/.bashrc.common" fi