cheat.sh 936 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. # Check dependencies
  3. [ -z "$(which fd 2>/dev/null)" ] && echo "[-] You need fd installed" && exit 1
  4. [ -z "$(which rg 2>/dev/null)" ] && echo "[-] You need ripgrep (rg) installed" && exit 1
  5. [ -z "$(which fzf 2>/dev/null)" ] && echo "[-] You need fzf installed" && exit 1
  6. # Set the path to the cheatncheck repo here
  7. cheatsheets="/home/juan/documents/checkncheat/"
  8. # check if the cheatsheets dir. exists.
  9. [ ! -d "$cheatsheets" ] && echo "[-] Cheatsheet folder does not exist." && exit 1
  10. # if yes, switch to that dir.
  11. cd $cheatsheets
  12. if [ $# -eq 0 ] ; then
  13. vim -R -c "Goyo 90%" "$(fzf)"
  14. exit 1
  15. fi
  16. # Option Parsin
  17. while getopts ":glws:p" options ; do
  18. case "${options}" in
  19. l) fd -t f \.md -x echo {/.} ;;
  20. p) echo $cheatsheets ;;
  21. w) vim -c "Goyo 90%" "$(fzf)" ;;
  22. g) vim -R -c "Goyo 90%" "$(fzf)" -g ;;
  23. s) rg "${OPTARG}" ;;
  24. *) echo 'Invalid Argument' ;;
  25. esac
  26. done