# Alias deprecated youtube-dl to yt-dlp
if which yt-dlp &>/dev/null; then
    alias youtube-dl="yt-dlp"
fi

# Alias to .local/venv programs
# Should probably move to symlinks
if ! which xq &>/dev/null; then
    alias xq="${HOME}/.local/venv/xq/bin/xq"
fi
if ! which black &>/dev/null; then
    alias black="${HOME}/.local/venv/black/bin/black"
fi
if ! which blackd &>/dev/null; then
    alias blackd="${HOME}/.local/venv/black/bin/blackd"
fi

if [[ "$(uname)" == "Darwin" ]] && ! which tac &>/dev/null; then
    alias tac='tail -r'
fi

# Nicer history
alias h='history 1 | tail -r | bat --style=plain --language=zsh'

# Set up ls aliases
if which exa &>/dev/null; then
    alias ls='exa --classify --group-directories-first --git'
    alias tree='exa --classify --group-directories-first --git --tree --git-ignore'
elif which lsd &>/dev/null; then
    alias ls='lsd'
    alias tree='lsd --tree'
elif [[ $(uname) = 'Darwin' ]]; then
    if which gls &>/dev/null; then
        alias ls='gls --color=tty --classify --time-style long-iso --human-readable'
    else
        alias ls='ls -GFh -D "%Y-%m-%d %H:%M"'
    fi
else
    alias ls='ls --color=tty --classify --time-style long-iso --human-readable'
fi
alias l='ls -l'
alias ll='ls -la'

# Coloured + VCS / common unwanted dir grep
_GREP_EXCLUDE='{.bzr,CVS,.git,.hg,.svn,.idea,.tox,venv}'
if which grep &>/dev/null; then
    alias grep="grep --color=auto --exclude-dir=${_GREP_EXCLUDE}"
fi
if which egrep &>/dev/null; then
    alias egrep="egrep --color=auto --exclude-dir=${_GREP_EXCLUDE}"
fi
if which fgrep &>/dev/null; then
    alias fgrep="fgrep --color=auto --exclude-dir=${_GREP_EXCLUDE}"
fi

if which todo.sh &>/dev/null; then
    alias t='todo.sh'
    alias tls='todo.sh ls | head -n 10'
    alias tl='todo.sh ls | less'
fi

# Colorise
if which ip &>/dev/null; then
    alias ip='ip -c'
fi
if which watch &>/dev/null; then
    alias watch='watch --color'
fi

# Arch stuff
if which yay &>/dev/null; then
    alias yay='sudo -u aurbuilder yay'
fi
if which pacman &>/dev/null; then
    alias pacman='pacman --color auto'
fi
if which pactree &>/dev/null; then
    alias pactree='pactree --color'
fi

# Date stuff
alias isodate='date +%Y-%m-%d'
alias isodatetime='date +%Y-%m-%dT%H:%M:%S%z'
alias pdate='date +"%Y-%m-%d %H:%M %z"'

# Force myself to use better things
if which bat &>/dev/null; then
    alias cat='bat'
fi

# Trash instead of rm
if which trash &>/dev/null; then
    alias rm='trash'
fi

# prettyping
if which prettyping &>/dev/null; then
    alias pping='prettyping --nolegend'
fi

# Use open as xdg-open on macOS
if ! which xdg-open &>/dev/null && which open &>/dev/null; then
    alias xdg-open='open'
fi

# shorthand for dumping QR codes in CLI
if which qrencode &>/dev/null; then
    alias qr='qrencode -t UTF8 -o -'
    alias qri='qrencode -t UTF8i -o -'
fi

# Generic dir aliases
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
alias -g ......='../../../../..'

alias -- -='cd -'
alias 1='cd -1'
alias 2='cd -2'
alias 3='cd -3'
alias 4='cd -4'
alias 5='cd -5'
alias 6='cd -6'
alias 7='cd -7'
alias 8='cd -8'
alias 9='cd -9'

alias dh='dirs -v'