123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/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
- function usage {
- echo "cheat.sh - cheatsheet reader"
- echo "Options:"
- echo " -h print help/usage"
- echo " -l list all files"
- echo " -p print cheatsheets path"
- echo " -w writable"
- echo " -g open in gvim"
- echo " -s search for string in <arg> using ripgrep"
- echo " -i interactive menu with dmenu"
- }
- # select the files using a dmenu/rofi interface and display em with md-viewer
- function interactive {
- cs=`fd .md$ $cheatsheets | dmenu -i -l 20`
- echo $cs > /tmp/lul
- #nohup md-viewer $cs >&2 2>/dev/null &
- $HOME/.scripts/tools/md-viewer "$cs"
- }
- # Set the path to the cheatncheck repo here
- if [ "$CHEAT" = "" ]; then
- cheatsheets="$HOME/documents/cheatsheets/"
- else
- cheatsheets="$CHEAT"
- fi
- # 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)"
- chosen_cheatsheet=`fzf`
- md-viewer "$chosen_cheatsheet"
- exit 1
- fi
- # Option Parsin
- while getopts ":ghlws:pi" options ; do
- case "${options}" in
- h) usage ;; # print help/usage
- l) fd -t f \.md -x echo {/.} ;; # list all files
- p) echo $cheatsheets ;; # print cheatsheets path
- w) vim -c "Goyo 90%" "$(fzf)" ;; # writable
- g) vim -R -c "Goyo 90%" "$(fzf)" -g ;; # open in gvim
- s) rg "${OPTARG}" ;; # search for string in <arg> using ripgrep
- i) interactive ;; # interactive dmenu/rofi menu
- *) echo 'Invalid Argument' ;; # Argument not available
- esac
- done
|