Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created July 10, 2012 03:43
Show Gist options
  • Save prabirshrestha/3080836 to your computer and use it in GitHub Desktop.
Save prabirshrestha/3080836 to your computer and use it in GitHub Desktop.
dotfiles install
#!/bin/bash
set -e
if [ -d ~/.dotfiles ]
then
echo "You already have .dotfiles installed. You'll need to remove ~/.dotfiles if you want to install"
exit 1
fi
echo "Cloning .dotfiles"
hash git >/dev/null && /usr/bin/env git clone --recursive https://github.com/prabirshrestha/dotfiles.git ~/.dotfiles || {
echo "git not installed"
exit 2
}
UNAME=$(uname)
OS=
if [[ "$UNAME" == 'Linux' ]]; then
OS="linux"
elif [[ "$UNAME" == 'Darwin' ]]; then
OS="mac"
elif [[ "$UNAME" == CYGWIN* || "$UNAME" == MINGW* ]]; then
OS="windows"
fi
skip_all=false
overwrite_all=false
backup_all=false
if [[ "$OS" == 'windows' ]]; then
CMDHOMEDIR=`cmd //c "echo %USERPROFILE%"`
fi
for src_path in ~/.dotfiles/*/*.symlink; do
overwrite=false
backup=false
skip=false
src_basename=`basename "$src_path"`
dest_path=`echo "$HOME/.$src_basename" | sed "s/\.symlink$//"`
if [ "$OS" == "windows" ]; then
src_path_normalized=`echo ${src_path/$HOME/$CMDHOMEDIR}`
dest_path_normalized=`echo "$CMDHOMEDIR\.$src_basename" | sed "s/\.symlink$//"`
else
src_path_normalized="$dest_path"
dest_path_normalized="$src_path"
fi
if [[ "$OS" == 'windows' ]]; then
if test -d "$src_path"; then
is_dir="/d"
else
is_dir=
fi
fi
if [ -e "$dest_path" ]; then
if [[ $skip_all = true || $overwrite_all = true || $backup_all = true ]]; then
loop=false
else
loop=true
fi
while [[ $loop = true ]]; do
read -p "File already exists: $dest_path_normalized, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite All, [b]ackup, [B]backup all " answer
case $answer in
o ) overwrite=true; break;;
b ) backup=true; break;;
O ) overwrite_all=true; break;;
B ) backup_all=true; break;;
S ) skip_all=true; break;;
s ) skip=true; break;;
esac
done
if [ $skip_all = false ]; then
if [ $skip = false ]; then
echo "Copying $dest_path_normalized"
fi
fi
else
if [ "$OS" == "windows" ]; then
cmd.exe /c "mklink $is_dir \"$dest_path_normalized\" \"$src_path_normalized\""
else
ln -s $dest_path_normalized $src_path_normalized
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment