#!/bin/bash echo "#########################" echo "# #" echo "# installing dotfiles #" echo "# #" echo "#########################" BACKUP_DIR="backup-$(date '+%Y-%m-%d_%H-%M-%S')" MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" CONFIG_MY_PATH="${MY_PATH/$HOME/\$\{HOME\}}" mkdir "$BACKUP_DIR" function cecho() { if [ -z "$2" ] ; then echo "$1" else case $1 in red) echo -e "\e[0;31m$2\e[0m" ;; green) echo -e "\e[0;32m$2\e[0m" ;; yellow) echo -e "\e[0;33m$2\e[0m" ;; cyan) echo -e "\e[1;36m$2\e[0m" ;; purple) echo -e "\e[0;35m$2\e[0m" ;; white) echo -e "\e[1;37m$2\e[0m" ;; ask) echo -ne "\e[1;37m$2\e[0m" ;; *) echo -e "\e[0;37m$2\e[0m" ;; esac fi } function backup_file() { file="${1}" if [ -e "$file" ] ; then if [ -d "$file" ] ; then cecho purple " - Moving old '$file' directory ..." else cecho purple " - Moving old '$file' file ..." fi mv "$file" "${BACKUP_DIR}/$(basename "${file}")" else cecho yellow " ! File '$file' not found! " fi } function symlink() { # usage: symlink name="${1}" cecho green " + Creating symlink to '$2' ..." ln -s "$2" "$name" } function ask() { cecho ask " ? Install file '$1'? [N/y] " read -r c if [ "$c" == "y" ] || [ "$c" == "Y" ] ; then backup_file "$1" symlink "$1" "$2" fi } ####### # vim # ####### cecho cyan "Installing vim config ..." backup_file "$HOME/.vim" backup_file "$HOME/.vimrc" symlink "$HOME/.vim" "${MY_PATH}/vim" symlink "$HOME/.vimrc" "${MY_PATH}/vim/vimrc" if command -v vim >/dev/null 2>&1; then cecho green " + Installing plugins ... " vim -nE +"colorscheme default" +PluginInstall +qall else cecho yellow " ! Vim is not installed!" cecho yellow " ! to install the plugins execute:" cecho yellow " ! vim -nE +\"colorscheme default\" +PluginInstall +qall" fi ####### # zsh # ####### cecho cyan "Installing zsh config" backup_file "$HOME/.zsh" backup_file "$HOME/.zshrc" # check if grml is installed grep grml\.org /etc/zsh/zshrc > /dev/null if [ $? -ne 0 ] ; then echo " + Installing grml ..." wget -O "$HOME/.zshrc" http://git.grml.org/f/grml-etc-core/etc/zsh/zshrc cecho yellow " ! You might wanna install grml-zsh-config using your packet manager" cecho yellow " ! and remove the .zshrc file in your home directory. " else cecho green " . grml-zsh-config is already installed :-)" # prevent configuration dialog if [ ! -f "$HOME/.zshrc" ] ; then cecho green " + Creating empty .zshrc" echo "# empty" > "$HOME/.zshrc" fi fi symlink "$HOME/.zsh" "${MY_PATH}/zsh" symlink "$HOME/.zshrc.local" "${MY_PATH}/zsh/zshrc.local" while [ ! "$MTYPE" == "PC" ] && [ ! "$MTYPE" == "SERVER" ] ; do cecho ask " ? Is this a server of a PC? [s|p] > " read -r mt case $mt in [Ss]*) MTYPE="SERVER";; [Pp]*) MTYPE="PC";; *) cecho red " ! Invalid input";; esac done git clone git://github.com/zsh-users/zsh-autosuggestions "$HOME/.zsh/zsh-autosuggestions" cecho green " + Creating .zshrc.pre ... " ( echo "# Path to your oh-my-zsh configuration." echo "ZSH=${CONFIG_MY_PATH}/.zsh" echo "# current user" echo "export DEFAULT_USER=\"\$(whoami)\"" echo "# machine type" echo "export MTYPE=\"$MTYPE\"" ) > "$HOME/.zshrc.pre" ######## # tmux # ######## cecho cyan "Installing tmux config" backup_file "$HOME/.tmux.conf" symlink "$HOME/.tmux.conf" "${MY_PATH}/tmux/tmux.conf" ###### # i3 # ###### cecho cyan "Installing i3 config" if [ "$MTYPE" == "PC" ] ; then backup_file "$HOME/.i3" backup_file "$HOME/.i3status.conf" symlink "$HOME/.i3" "${MY_PATH}/i3" symlink "$HOME/.i3status.conf" "${MY_PATH}/i3/i3status.conf" ask "$HOME/.xprofile" "${MY_PATH}/xprofile" else cecho yellow " > skipping " fi ############### # other stuff # ############### cecho cyan "Symlinking other stuff ..." if [ "$MTYPE" == "PC" ] ; then ask "$HOME/.xinitrc" "${MY_PATH}/xinitrc" ask "$HOME/.pentadactylrc" "${MY_PATH}/pentadactylrc" ask "$HOME/.gitconfig" "${MY_PATH}/gitconfig" else backup_file "$HOME/.gitconfig" symlink "$HOME/.gitconfig" "${MY_PATH}/gitconfig" fi backup_file "$HOME/bin" symlink "$HOME/bin" "${MY_PATH}/bin"