#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
WM=i3
if (( $# == 1 ))
then
  WM=$1
fi

if [ -d /etc/X11/xinit/xinitrc.d ]; then
  for f in /etc/X11/xinit/xinitrc.d/*; do
    [ -x "$f" ] && . "$f"
  done
  unset f
fi

export EDITOR="vim"
export CUPS_GSSSERVICENAME=HTTP

[[ -f ~/.Xresources ]] && xrdb -merge ~/.Xresources

volnoti &
owncloud &

rm -f "~/${WM}.log.old"
mv -f "~/${WM}.log" "~/${WM}.log.old"
rm -f "~/${WM}.log"
rm -f "~/${WM}.log"

if [ "$WM" = "i3" ]; then
    # Generate i3 config file
    i3config="/tmp/i3_${USER}_config"
    rm -f $i3config

    if [ -f ~/.i3/base.config ]; then
        cat ~/.i3/base.config >> $i3config
    fi

    if [ "`hostname`" = "kubaArch" ] && [ -f ~/.i3/home.config ]; then
        cat ~/.i3/home.config >> $i3config
    elif [ "`hostname`" = "JakubArch" ] && [ -f ~/.i3/work.config ]; then
        cat ~/.i3/work.config >> $i3config
    fi
    #exec i3 -c $i3config -V >> ~/${WM}.log 2>&1
    exec i3 -c $i3config
else
    exec $WM >> "~/${WM}.log" 2>&1
fi
