alias mk="make -j${NPROC:-1}"
alias mkc='make clean'
alias mki='make install'
alias mku='make uninstall'
alias mks='make -s install'
alias mkt='make test'
alias mkki='make ; make install'
alias mka='make clean ; make ; make install'

alias py=python3

# activate my PS1 git branch detection after branch switching
gud() { command gud "$@" ; cd . ; }

scfg() {
    ${PLUMBER:-${EDITOR:-vi}} ~/src/suckless/$1/cfg/config.h
}

# watch a file and do an action as its contents changes
iwaitdo() {
    file=$1
    shift
    [ -f "$file" ] || { >&2 echo "No such file: $file" ; return 1 ; }
    [   "$1"     ] || { >&2 echo "No action given."    ; return 1 ; }

    while inotifywait -e modify "$file" ; do eval "$*" ; done
}

# editor wrapper
v() {
    if [ "$1" ] && [ -d "$1" ] ; then
        >&2 printf 'Error: %s is a directory.\n' "${1%/}"
        return 1
    elif [ "$1" ] && [ ! -f "$1" ] ; then
        printf "File '%s' does not exist.\nCreate it? (y/n): " "$1"
        read -r ans
        case $ans in
            *y*)
                ;;
            *)
                return
        esac
    # if not provided a file to open, open scratchpad
    elif [ -z "$1" ] ; then
        set ~/files/scratchpad.md
    fi

    ${EDITOR:-vi} -n -- "$@"
}

alias md2html='pandoc -f markdown'
mdff() {
    if [ -f "$1" ] ; then
        pandoc -f markdown "$1" > /tmp/out.html &&
        ${BROWSER:-firefox} /tmp/out.html
    fi
}

