helper.sh 706 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. function tutlist () {
  3. find tuts/ -type f | sort
  4. }
  5. export CURR_LIST_POS=1
  6. export MAX_LIST_POS=$(tutlist | wc -l)
  7. export CURR_LIST_FILE=$(tutlist | head -n1 | tail -n1)
  8. function tutspos() {
  9. CURR_LIST_FILE=$(tutlist | head -n${1} | tail -n1)
  10. }
  11. function tutcurr() {
  12. tutspos "${CURR_LIST_POS}"
  13. vim "${CURR_LIST_FILE}"
  14. }
  15. function tutprev() {
  16. [ "${CURR_LIST_POS}" -le 1 ] &&
  17. echo "already at first tutorial" &&
  18. return
  19. CURR_LIST_POS=$((CURR_LIST_POS - 1))
  20. tutcurr
  21. }
  22. function tutnext() {
  23. [ "${CURR_LIST_POS}" -ge "${MAX_LIST_POS}" ] &&
  24. echo "already at last tutorial" &&
  25. return
  26. CURR_LIST_POS=$((CURR_LIST_POS + 1))
  27. tutcurr
  28. }