#!/bin/sh
# General handler for compiling files
# stolen from BrodieRobertson 

file=$(readlink -f "$1")
base=$(echo "$file" | sed 's/\..*//')

handlebang() {
  bang=$(head -n 1 "$file")
  case "$bang" in
    *!/bin/sh|*!/bin/bash|*!/bin/zsh) "$file" ;;
    *!/bin/perl) perl "$file" ;;
    *!/bin/python) python "$file" ;;
    *) echo "Can't compile" ;;
  esac
}

case "$1" in
    *.md) pandoc "$file" -o "$base".pdf ;;
    *.py) python "$file" ;;
    *.perl) perl "$file" ;;
    *) handlebang ;;
esac
