Skip to content

Instantly share code, notes, and snippets.

@oogali
Created December 17, 2013 18:27
Show Gist options
  • Save oogali/8010116 to your computer and use it in GitHub Desktop.
Save oogali/8010116 to your computer and use it in GitHub Desktop.
dotfiles magic
#!/bin/sh
set -e
setup_pathogen() {
mkdir -p ${HOME}/.vim/autoload ${HOME}/.vim/bundle
curl -Sso ${HOME}/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
}
setup_mutt() {
mkdir -p ${HOME}/.mutt/hcache
}
setup_ssh() {
mkdir -p ${HOME}/.ssh/mux
if [ ! -f "${HOME}/.ssh/known_hosts" ]; then
touch ${HOME}/.ssh/known_hosts
fi
}
setup_rbenv() {
rbenv_path="${HOME}/.rbenv"
if [ -d "${rbenv_path}" ]; then
echo "==> rbenv"
cd ${rbenv_path} && git pull
echo "==> rbenv/ruby-build"
if [ -d "${rbenv_path}/plugins/ruby-build" ]; then
cd ${rbenv_path}/plugins/ruby-build && git pull
else
git clone https://github.com/sstephenson/ruby-build.git ${rbenv_path}/plugins/ruby-build
fi
else
echo "==> rbenv and ruby-build"
git clone https://github.com/sstephenson/rbenv.git ${rbenv_path}
git clone https://github.com/sstephenson/ruby-build.git ${rbenv_path}/plugins/ruby-build
fi
}
clone_bundle() {
if [ -z "${1}" ]; then
return 1
fi
repo=${1}
name=$(basename ${1} | sed 's/\.git$//')
target="${HOME}/.vim/bundle/${name}"
echo "==> ${name}"
if [ -d "${target}/.git" ]; then
cd ${target} && git pull
else
git clone ${repo} ${HOME}/.vim/bundle/${name}
fi
}
install_dotfile() {
if [ -z "${1}" ]; then
return 1
fi
dotfile=${1}
echo "==> ${dotfile}"
if [ -f "${HOME}/${dotfile}" ]; then
difflines=$(diff -U4 ${HOME}/${dotfile} ${dotfile} || true)
if [ -z "${difflines}" ]; then
return 0
fi
echo "${difflines}"
echo
/bin/echo -n "ours, theirs, or merge? "
read action
case ${action} in
[oO][uU][rR][sS])
# skip
;;
[tT][hH][eE][iI][rR][sS])
cp ${dotfile} ${HOME}/${dotfile}
;;
[mM][eE][rR][gG][eE])
vim -O2 ${HOME}/${dotfile} ${dotfile}
;;
*)
# loop again
install_dotfile ${dotfile}
;;
esac
else
cp ${dotfile} ${HOME}/${dotfile}
fi
}
pushd ${PWD} >/dev/null
setup_rbenv
setup_mutt
setup_pathogen
clone_bundle 'https://github.com/bling/vim-airline.git'
clone_bundle 'https://github.com/majutsushi/tagbar.git'
clone_bundle 'https://github.com/chrisbra/csv.vim.git'
clone_bundle 'https://github.com/scrooloose/syntastic.git'
clone_bundle 'https://github.com/scrooloose/nerdtree.git'
clone_bundle 'https://github.com/jmcantrell/vim-virtualenv.git'
clone_bundle 'https://github.com/tpope/vim-fugitive.git'
clone_bundle 'https://github.com/quanganhdo/grb256.git'
popd >/dev/null
for dotfile in $(find . -type f ! -name '*.sw[a-p]' ! -name 'setup.sh' ! -path '*/.git/*'); do
install_dotfile ${dotfile}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment