Mobile-responsive personal website, generated using Hugo. https://kevin-mok.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.6 KiB

  1. ---
  2. title: Wallpaper Playlist for pywal
  3. date: 2019-02-16T11:42:33-05:00
  4. draft: true
  5. ---
  6. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
  7. tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
  8. vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
  9. no sea takimata sanctus est Lorem ipsum dolor sit amet.
  10. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
  11. tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
  12. vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
  13. no sea takimata sanctus est Lorem ipsum dolor sit amet.
  14. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
  15. tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
  16. vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
  17. no sea takimata sanctus est Lorem ipsum dolor sit amet.
  18. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
  19. tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
  20. vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
  21. no sea takimata sanctus est Lorem ipsum dolor sit amet.
  22. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
  23. tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
  24. vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
  25. no sea takimata sanctus est Lorem ipsum dolor sit amet.
  26. {{< highlight sh >}}
  27. #!/bin/bash
  28. shuffle_cache="shuffle.txt"
  29. regen_flag=0
  30. dir=""
  31. function usage_msg() {
  32. # echo "usage: shuffler [-r] [dir_name]"
  33. cat <<-EOF
  34. Usage: shuffler [-r] [dir_name]
  35. -r: regenerate the shuffle cache
  36. EOF
  37. }
  38. # parse for regen_flag{{{
  39. while getopts ":r" opt; do
  40. case $opt in
  41. r)
  42. echo "-r was triggered!" >&2
  43. regen_flag=1
  44. ;;
  45. \?)
  46. echo "Invalid flag: -$OPTARG" >&2
  47. usage_msg
  48. exit 1
  49. ;;
  50. esac
  51. done
  52. #}}}
  53. # set dir {{{ #
  54. shift $((OPTIND-1))
  55. # if no dir, use pwd
  56. if [[ "$#" -eq 0 ]]; then
  57. dir=$(pwd)
  58. elif [[ "$#" -gt 1 ]] || [[ ! -d "$1" ]]; then
  59. usage_msg
  60. exit 1
  61. else
  62. dir="$1"
  63. fi
  64. # }}} set dir #
  65. # rebuild shuffle cache if regen_flag, doesn't exist or file empty
  66. if [[ "$regen_flag" -eq 1 ]] || [[ ! -f "$dir"/"$shuffle_cache" ]] || \
  67. [[ "$(head -n 1 "$dir"/"$shuffle_cache")" = "" ]]; then
  68. find "$dir"/* ! -name "$shuffle_cache" -type f | shuf > "$dir"/"$shuffle_cache"
  69. fi
  70. head -n 1 "$dir"/"$shuffle_cache"
  71. printf '%s\n\n' "$(sed '1d' "$dir"/"$shuffle_cache")" > "$dir"/"$shuffle_cache"
  72. # vim: set tabstop=2 shiftwidth=2 expandtab:
  73. {{< /highlight >}}