ZSH=$HOME/.ohmyzsh
DOTCONFDIR=$HOME/.dotconfigs

URL_OMZSH="https://github.com/robbyrussell/oh-my-zsh.git"

### Install oh-my-zsh

if [[ ! -d $ZSH ]]; then
    if curl --output /dev/null --silent -m 1  --head --fail "$URL_OMZSH"; then
	      echo "Installing Oh My ZSH"
	      git clone "$URL_OMZSH" $ZSH
    fi
fi


### Configure oh-my-zsh

ZSH_THEME="pygmalion"

plugins=(
    git
    pip
    docker-compose
    python
    virtualenvwrapper
)

source $ZSH/oh-my-zsh.sh


### Configure zsh

HISTSIZE=20000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
# hosts=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })


### Generic Setup
export LC_ALL='en_US.UTF-8'
export WORKON_HOME=~/.virtualenvs

if [[ $(uname) = "Darwin" ]]; then
    PATH=$PATH:~/Library/Anaconda/bin
fi

source $DOTCONFDIR/dotconf.sh

### Shell function definition

function sortimages () {
    case $1 in
	-d)
        shift
		for file in $@; do
		    DST=`identify -format "%[Exif:DateTimeOriginal]" $file | head -1 | awk '{print $1":"$2}' | awk -F':' '{print $1$2$3"-"$4$5$6}' | awk -F'.' '{print $1 }' | awk -F'::' '{print $1}'`
		    DST=`echo $DST.jpg`
		    echo mv $file $DST;
		    mv $file $DST;
		    chmod 640 $DST;
		done
		;;
	*)
		echo "Rename files"
		echo "Usage: sortimages <options> <file-selection> <suffix>"
		echo "   <file-selection> : for example *.JPG"
		echo "   <suffix>         : rename to "'$date'"-'$time'-suffix.jpg"
		echo "   <options>        : -d   rename the files"
		echo -n
		for file in $@; do
		    DST=`identify -format "%[Exif:DateTimeOriginal]" ${file} | head -1 | awk '{print $1":"$2}' | awk -F':' '{print $1$2$3"-"$4$5$6}' | awk -F'.' '{print $1 }' | awk -F'::' '{print $1}'`
		    DST=${DST}'.jpg'
		    echo mv ${file} ${DST};
		done
		;;
esac
}

### Alias configuration

if [[ $(uname) = "Linux" ]]; then
    alias em='emacs -nw'
    alias ec='emacsclient -c'
    alias grep='grep --color'
    alias ls='ls --color'
    alias l='ls -lh --color'
    alias open='xdg-open'
fi

if [[ $(uname) = "Darwin" ]]; then
    PATH=$PATH:~/Library/Anaconda/bin
    alias emacs='/usr/local/opt/emacs/bin/emacs'
    alias em='emacs -nw'
    alias ec='/usr/local/opt/emacs/bin/emacsclient -c'
    alias grep='grep --color=always'
    alias l='ls -lh'
fi


### Conda setup on MacOS

if [[ $(uname) = "Darwin" ]]; then
    source  /Users/mschoengens/Library/Anaconda/etc/profile.d/conda.sh
fi
