#!/usr/bin/env bash

# Remove zsh completion dump
rm ~/.zcompdump

# Remove vim config directory
rm -rf ~/.vim-backup
mv ~/.vim ~/.vim-backup
mv ~/.mutt ~/.mutt-backup
mv ~/.muttrc ~/.muttrc.bk

mkdir -p ~/.vim/{autoload,pack/shapeshed/start,colors,doc,ftplugin,plugin,spell,syntax}
pushd ~/.vim/spell
wget -r -nH --cut-dirs=5 -nc ftp://ftp.vim.org//pub/vim/runtime/spell
popd

# Install oh-my-zsh
rm -rf ~/.oh-my-zsh
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

mkdir -p ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting

touch ~/.zshrc-local

# Copy the japanese part if needed
if [ "$1" == '--jp' ]
then
    rsync -av ./jp/ ~/
fi

# Copy the graphical part if needed
if [ "$1" == '--graphic' ]
then
    rsync -av ./graphic/ ~/
    fc-cache -vf ~/.fonts
    gsettings set org.gnome.desktop.interface gtk-theme "Numix"
    gsettings set org.gnome.desktop.wm.preferences theme "Numix"
    gsettings set org.gnome.desktop.interface icon-theme 'Numix'
    gsettings set org.gnome.desktop.interface font-name 'Ubuntu 9'
    gsettings set org.gnome.desktop.interface monospace-font-name 'Ubuntu Mono for Powerline 9'
    gsettings set org.gnome.desktop.interface buttons-have-icons true
    gconftool --type=string --set /desktop/cinnamon/windows/theme "Numix"
    gconftool-2 --type=string --set /apps/metacity/general/theme "Numix"
    gsettings set org.cinnamon.theme name 'Flatty flakes'
    #gsettings set org.cinnamon.desktop.background picture-uri "file://$HOME/.cinnamon/backgrounds/bg_fluffsplosion.jpeg"
    gsettings set org.cinnamon.desktop.background picture-options 'stretched'
    gsettings set org.cinnamon.desktop.background color-shading-type 'solid'
    gsettings set org.cinnamon.desktop.background primary-color '#000000'
    gsettings set org.cinnamon.desktop.background secondary-color '#000000'
    gsettings set org.cinnamon.desktop.interface gtk-theme "Numix"
    gsettings set org.cinnamon.desktop.interface icon-theme 'Numix'
    gsettings set org.cinnamon.desktop.interface font-name 'Ubuntu 9'
    gsettings set org.cinnamon.desktop.interface buttons-have-icons true
    gsettings set org.cinnamon.desktop.wm.preferences num-workspaces 4
    gsettings set org.cinnamon.desktop.wm.preferences theme 'Numix'
    gsettings set org.cinnamon.desktop.wm.preferences titlebar-font 'Ubuntu Medium 10'
    gsettings set org.cinnamon.muffin.keybindings minimize "['<Primary><Alt>r']"
fi

# Copy the common part
rsync -av ./common/ ~/

# Adjust the tmux conf
sed -i "s/REPLACEMEWITHFIRSTLETTEROFHOSTNAME/`expr substr \`hostname\` 1 1`/g" ~/.tmux.conf

######### VIM Config ###########

# Install jedi plugin for vim
rm -rf ~/.vim/pack/shapeshed/start/jedi
git clone https://github.com/davidhalter/jedi-vim.git ~/.vim/pack/shapeshed/start/jedi

# Install nerdtree for vim
rm -rf ~/.vim/pack/shapeshed/start/nerdtree
git clone https://github.com/scrooloose/nerdtree.git ~/.vim/pack/shapeshed/start/nerdtree

# Install xmledit for vim
rm -rf ~/.vim/pack/shapeshed/start/xmledit
git clone https://github.com/sukima/xmledit.git ~/.vim/pack/shapeshed/start/xmledit
pushd ~/.vim/pack/shapeshed/start/xmledit
make install
popd

# Install syntastic plugin
rm -rf ~/.vim/pack/shapeshed/start/syntastic
git clone --recursive https://github.com/scrooloose/syntastic.git ~/.vim/pack/shapeshed/start/syntastic

# Install autoclose plugin
rm -rf ~/.vim/pack/shapeshed/start/autoclose
git clone https://github.com/Townk/vim-autoclose.git ~/.vim/pack/shapeshed/start/autoclose

# Install tagbar plugin
rm -rf ~/.vim/pack/shapeshed/start/tagbar
git clone https://github.com/majutsushi/tagbar ~/.vim/pack/shapeshed/start/tagbar

# Install vcscommand plugin
rm -rf ~/.vim/pack/shapeshed/start/vcscommand
git clone https://github.com/vim-scripts/vcscommand.vim.git ~/.vim/pack/shapeshed/start/vcscommand

# Install easytag plugin
#rm -rf ~/.vim/pack/shapeshed/start/easytag
#git clone https://github.com/vim-scripts/easytags.vim.git ~/.vim/pack/shapeshed/start/easytag

# Install closetag plugin
rm -rf ~/.vim/pack/shapeshed/start/closetag
git clone https://github.com/vim-scripts/closetag.vim.git ~/.vim/pack/shapeshed/start/closetag

# Install css3 syntax
rm -rf ~/.vim/pack/shapeshed/start/vim-css3-syntax
git clone https://github.com/hail2u/vim-css3-syntax ~/.vim/pack/shapeshed/start/vim-css3-syntax

# Install less syntax
rm -rf ~/.vim/pack/shapeshed/start/vim-less
git clone https://github.com/groenewege/vim-less.git ~/.vim/pack/shapeshed/start/vim-less

# Install notes plugin
rm -rf ~/.vim/pack/shapeshed/start/misc
git clone https://github.com/xolox/vim-misc.git ~/.vim/pack/shapeshed/start/misc

rm -rf ~/.vim/pack/shapeshed/start/notes
git clone https://github.com/xolox/vim-notes.git ~/.vim/pack/shapeshed/start/notes

# Install better highlighting for Python
rm -rf ~/.vim/pack/shapeshed/start/python-syntax
git clone https://github.com/hdima/python-syntax.git ~/.vim/pack/shapeshed/start/python-syntax

# Install better support of colorscheme
rm -rf ~/.vim/pack/shapeshed/start/csapprox
git clone https://github.com/godlygeek/csapprox.git ~/.vim/pack/shapeshed/start/csapprox

# Install support of coffeescript
rm -rf ~/.vim/pack/shapeshed/start/coffeescript
git clone https://github.com/kchmck/vim-coffee-script.git ~/.vim/pack/shapeshed/start/coffeescript

# Install of multiple cursors
rm -rf ~/.vim/pack/shapeshed/start/vim-multiple-cursors
git clone https://github.com/terryma/vim-multiple-cursors.git ~/.vim/pack/shapeshed/start/vim-multiple-cursors

# Install of HTML5 colors
rm -rf ~/.vim/pack/shapeshed/start/html5.vim
git clone https://github.com/othree/html5.vim.git ~/.vim/pack/shapeshed/start/html5.vim

# Install vim airline
rm -rf ~/.vim/pack/shapeshed/start/vim-airline
git clone https://github.com/vim-airline/vim-airline ~/.vim/pack/shapeshed/start/vim-airline
rm -rf ~/.vim/pack/shapeshed/start/vim-airline-themes
git clone https://github.com/vim-airline/vim-airline-themes ~/.vim/pack/shapeshed/start/vim-airline-themes

# Install fugitive
rm -rf ~/.vim/pack/shapeshed/start/fugitive
git clone https://github.com/tpope/vim-fugitive.git ~/.vim/pack/shapeshed/start/fugitive

# Install vim lucius
rm -rf ~/.vim/pack/shapeshed/start/lucius
git clone https://github.com/jonathanfilip/vim-lucius.git ~/.vim/pack/shapeshed/start/lucius

# Install vim renpy
rm -rf ~/.vim/pack/shapeshed/start/vim-renpy
git clone https://github.com/chaimleib/vim-renpy ~/.vim/pack/shapeshed/start/vim-renpy

# Install tmux-airline generator
rm -rf ~/.vim/pack/shapeshed/start/tmuxline
git clone https://github.com/edkolev/tmuxline.vim ~/.vim/pack/shapeshed/start/tmuxline

# Install promptline generator
rm -rf ~/.vim/pack/shapeshed/start/promptline
git clone https://github.com/edkolev/promptline.vim ~/.vim/pack/shapeshed/start/promptline

# Install Alt mappings
#rm -rf ~/.vim/pack/shapeshed/start/vim-alt-mappings
#git clone https://github.com/vim-utils/vim-alt-mappings.git ~/.vim/pack/shapeshed/start/vim-alt-mappings

# Install typescript for vim
rm -rf ~/.vim/pack/shapeshed/start/typescript-vim
git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/pack/shapeshed/start/typescript-vim

# Install languagetool for vim
rm -rf ~/.vim/pack/shapeshed/start/languagetool
git clone https://github.com/vim-scripts/LanguageTool.git ~/.vim/pack/shapeshed/start/languagetool

# Install minimap for vim
rm -rf ~/.vim/pack/shapeshed/start/vim-minimap
git clone https://github.com/severin-lemaignan/vim-minimap.git ~/.vim/pack/shapeshed/start/vim-minimap

# Install monochrome theme for vim
rm -rf ~/.vim/pack/shapeshed/start/vim-monochrome
git clone https://github.com/fxn/vim-monochrome.git ~/.vim/pack/shapeshed/start/vim-monochrome

# Install vimagit
rm -rf ~/.vim/pack/shapeshed/start/vimagit
git clone https://github.com/jreybert/vimagit ~/.vim/pack/shapeshed/start/vimagit

# Install Grammalecte
rm -rf ~/.vim/pack/shapeshed/start/vim-grammalecte
git clone https://github.com/dpelle/vim-Grammalecte.git ~/.vim/pack/shapeshed/start/vim-grammalecte

if [ -e ../homes-private/update-home.sh ]
then
    source ../homes-private/update-home.sh
fi
