#!/usr/bin/env zsh
# Eryn Wells <eryn@erynwells.me>

local system_ls=`which ls`
local has_gnu_ls
local ls_options

if $system_ls --version 2>&1 | grep GNU 1>/dev/null; then
    has_gnu_ls=1
    ls_options='--color=auto'
else
    has_gnu_ls=0
    ls_options='-G'
fi

alias ls="$system_ls $ls_options"
alias la="$system_ls -A $ls_options"
alias ll="$system_ls -l $ls_options"
alias l.="$system_ls -d $ls_options .*"

local dircolors_bin=`whence -p dircolors || whence -p gdircolors`
if [[ $has_gnu_ls -eq 1 && -n "$dircolors_bin" ]]; then
    if [[ -e "$HOME/.dircolors/$SYS.cfg" ]]; then
        dircolors="$HOME/.dircolors/$SYS.cfg"
    else
        dircolors="$HOME/.dircolors/default.cfg"
    fi

    eval `$dircolors_bin $dircolors`
fi
