#!/bin/sh

# Check dependencies
[ -z "$(which fd 2>/dev/null)" ] && echo "[-] You need fd installed" && exit 1
[ -z "$(which rg 2>/dev/null)" ] && echo "[-] You need ripgrep (rg) installed" && exit 1
[ -z "$(which fzf 2>/dev/null)" ] && echo "[-] You need fzf installed" && exit 1

# Set the path to the cheatncheck repo here
cheatsheets="/home/juan/documents/checkncheat/"

# check if the cheatsheets dir. exists.
[ ! -d "$cheatsheets" ] && echo "[-] Cheatsheet folder does not exist." && exit 1

# if yes, switch to that dir.
cd $cheatsheets

if [ $# -eq 0 ] ; then
    vim -R -c "Goyo 90%" "$(fzf)"
    exit 1
fi

# Option Parsin
while getopts ":glws:p" options ; do
    case "${options}" in
        l) fd -t f \.md -x echo {/.} ;;
        p) echo $cheatsheets ;;
        w) vim -c "Goyo 90%" "$(fzf)" ;;
        g) vim -R -c "Goyo 90%" "$(fzf)" -g ;;
        s) rg "${OPTARG}" ;;
        *) echo 'Invalid Argument' ;;
    esac
done