#!/bin/bash
# 
# SCRIPT NAME:
# .aliases
#
# AUTHOR:
# Severin Kaderli <severin@kaderli.dev>
#
# DESCRIPTION:
# This script is used to define aliases for commands.
#
# USAGE:
# This script is sourced by .bashrc

# Alias for clear because I sometimes type the DOS command instead
alias cls="clear"

# Alias for using lsd as ls replacement
alias ls='lsd'
alias la="ls -al"
alias lt="ls --tree"

# Alias for using bat as cat replacement
alias cat="bat"

# Aliases to access folders
if [ -d "${HOME}/dev" ]; then
    alias dev='cd ${HOME}/dev'
fi

if [ -d "${HOME}/dev/projects" ]; then
    alias pj='cd ${HOME}/dev/projects'
fi

if [ -d "${HOME}/downloads" ]; then
    alias dl='cd ${HOME}/downloads'
fi

if [ -d "${HOME}/documents" ]; then
    alias doc='cd ${HOME}/documents'
fi

if [ -d "${HOME}/dev/school" ]; then
    alias school='cd ${HOME}/dev/school'
fi

# Alias for opening my code editor
alias e='code'

# Other aliases
alias timestamp='date +%s'
alias interfaces='ip -o link show | cut -d ":" -f 2'
alias ztar='tar --zstd -cf'

function ebook-tools {
    if [ -z "${1}" ]; then
        echo "Please supply the book folder as argument."
        return
    fi

    docker run -it -v "${1}:/var/books" ebooktools/scripts:latest organize-ebooks.sh -v  --output-folder="/var/books/organized" "/var/books"
}

# Get Git log as markdown table
function git-markdown {
    echo "| Date | Author | Subject |"
    echo "|--|--|--|"
    git log --no-merge --pretty=format:"| %ai | %an | %s |"
}

function psql {
    docker run -p 5432:5432 --name psql -e POSTGRES_PASSWORD=password -d postgres
}