helpers.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. # This is a set of helper bash functions that are too small for their own file,
  3. # but useful enough to be worth `source`ing in your bashrc.
  4. # Faster general searching
  5. function vgsrc() {
  6. case $# in
  7. 1)
  8. vgstash list | grep -iE "$1"
  9. ;;
  10. 2)
  11. vgstash list "$1" | grep -iE "$2"
  12. ;;
  13. *)
  14. echo "usage: vgsrc [game name]"
  15. echo " or vgsrc [view name] [game name]"
  16. echo
  17. echo "Ex: vgsrc physical Borderlands"
  18. ;;
  19. esac
  20. }
  21. # Faster adding
  22. function vgadd() {
  23. vgstash add "$@"
  24. }
  25. # Shows you a list of *unique* game titles that you have beaten or completed.
  26. # This allows you to weed out the games you own or have beaten on more than one
  27. # platform.
  28. function vgub() {
  29. # TODO: improve
  30. vgstash list -w 80 | head -n 2
  31. vgstash list done -w 80 | sed -e '1,2d' | sort | uniq -w50 | sort -b -t'|' -k 2,2
  32. }
  33. # Shows you the titles of games that you own on more than one system.
  34. function vgmulti() {
  35. vgstash list owned -w 80 | sed -e '1,2d' | sort -b -t'|' -k 1,1 | uniq -d -w50 | cut -d'|' -f 1
  36. }
  37. # Prints the title and system of a random game that you need to beat.
  38. # This tool is great for deciding what to play to knock out the backlog.
  39. function vgrand() {
  40. local game=$(vgstash list playlog | sed -e '1,2d' | shuf -n 1 --random-source=/dev/random | cut -d '|' -f 1-2 | tr -s ' ' | sed -e 's: | :, for :' -e 's:\s$::')
  41. echo "You should play ${game}!"
  42. }
  43. # Filters your vgstash output by system. Depends on awk
  44. function vgsys() {
  45. local f='allgames'
  46. local s=''
  47. case $# in
  48. 1)
  49. # single arg means we want the default filter
  50. s="$1"
  51. ;;
  52. 2)
  53. f="$1"
  54. s="$2"
  55. ;;
  56. *)
  57. echo "USAGE: vgsys [FILTER] SYSTEM"
  58. echo
  59. echo "Show all games from a given system (and optionally, filter)."
  60. echo "Defaults to 'allgames' filter if the argument is missing."
  61. return
  62. ;;
  63. esac
  64. vgstash list $f -w 80 | awk 'BEGIN {FS="|"} $2 ~ /'$s'/'
  65. }