quests 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. # CC strlst
  3. # hastily written
  4. # but does the job
  5. # whatever
  6. ROOT="$HOME/.quests"
  7. COLS=$(expr $(stty size | cut -d' ' -f 2))
  8. splitline() {
  9. printf "\n +"
  10. printf %-$((COLS - 6))s | tr ' ' '-'
  11. printf "+ \n"
  12. }
  13. splititem() {
  14. number='-' && [ ! -z $1 ] && number=$1
  15. echo
  16. printf %-$((($COLS - 3) / 2))s
  17. echo "- ${number} -"
  18. }
  19. printitem() {
  20. [ $(printf "$*" | wc -c) -gt $(($COLS - 4)) ] && printf " $* " && return
  21. count=$(printf "$*" | wc -c)
  22. border=$((($COLS - count) / 2))
  23. printf %-$(($border))s
  24. echo -n $* | sed 's/_/ /g'
  25. printf %-$(($border))s
  26. echo
  27. }
  28. [ $(($(ls -1 "$ROOT" | wc -c))) -lt 2 ] && echo "nothing to do" && exit 0
  29. splitline
  30. # iterate over lines, not words
  31. IFS="
  32. "
  33. index=1
  34. for i in $(ls -1 "$ROOT"); do
  35. splititem ${index}
  36. printitem $i
  37. index=$((${index} + 1))
  38. done
  39. splitline