[
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 Lakshay Kalbhor\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "<img src=\"https://raw.githubusercontent.com/lakshaykalbhor/Thirsty/master/out.gif\">\n\n# Thirsty\n> zsh/bash script to remind you to drink water.\n\nIf you're like me and you spend a lot of time programming with the command line open, chances are that you forget about everything for hours, which includes drinking water.\n**At the end of the day I used to realise that I had not consumed enough water.**\nHence I created a bash/zsh script to remind me to drink water right on my command line.\n\n## How to use\n1. Copy the [thirsty.sh](thirsty.sh) file and paste it in your zshrc or bashrc or theme, etc.\n2. In your zshrc/theme/bashrc locate `PROMPT='$(some_function)'` or `PROMPT_COMMAND='$(some_function)'` for bash and add `drink_water` inside that function. *(This will be the case if you're using a theme)*\n3. If you can't locate `PROMPT`, then just add `PROMPT='$(drink_water)'` or `PROMPT_COMMAND='$(drink_water)'` for bash in the file.\n4. Set your time interval in the variable `WATER_TIME` in seconds, eg : `WATER_TIME=1200` sets it to 20 mins.\n5. Once notified, you can remove the message by simply typing `not_thirsty` in your command line.\n\n"
  },
  {
    "path": "thirsty.sh",
    "content": "#!/bin/sh\n\nWATER_TIME=${WATER_TIME:-1200} # Set time interval in seconds\nDRINK_WATER_CONF=\"${DRINK_WATER_CONF:-$HOME/.water}\"\n\ndrink_water() {\n  # If the file doesn't exist, create it\n  if [ ! -f $DRINK_WATER_CONF ]; then\n    date +%s > $DRINK_WATER_CONF\n  fi\n\n  # Tail is used to remain compatible with the pervious file format\n  next_time=$(($(tail -1 $DRINK_WATER_CONF) + $WATER_TIME))\n\n  if [ $next_time -lt $(date +%s) ]; then\n    echo -n \"💧 You're thirsty\"\n  fi\n}\n\nnot_thirsty() {\n  date +%s > $DRINK_WATER_CONF\n  echo \"Water is essential\"\n}\n\nnext_drink() {\n  next_time=$(($(cat $DRINK_WATER_CONF) + $WATER_TIME))\n  next_date=\"\"\n  # Mac's date command uses a different flag\n  case \"$(uname)\" in\n    'Darwin')\n      next_date=\"$(date -r $next_time)\"\n      ;;\n    *)\n      next_date=\"$(date --date=\"@$next_time\")\"\n      ;;\n  esac\n\n  echo \"Next drink at $next_date\"\n}\n"
  },
  {
    "path": "thirsty_test.sh",
    "content": "#!/bin/sh\n\n# Override default water time\nWATER_TIME=5\nDRINK_WATER_CONF=$PWD/test.water\n\nrm -f \"$DRINK_WATER_CONF\"\n\n./thirsty.sh\n\necho \"Running tests...\"\n\n# Test that drink_water returns nothing\nout=\"$(drink_water)\"\nif [ -n \"$out\" ]; then\n    echo \"drink_water error. Expected '', got '$out'\"\n    exit 1\nfi\n\nsleep \"$($WATER_TIME + 1)\"\n\n# Test that drink_water tells us it's time for a drink\nout=\"$(drink_water)\"\nexpected=\"💧 You're thirsty\"\nif [ \"$out\" != \"$expected\" ]; then\n    echo \"drink_water error. Expected '$expected', got '$out'\"\n    exit 1\nfi\n\n# Test that not_thirsty sets a new time\nbefore=\"$(cat \"$DRINK_WATER_CONF\")\"\nout=\"$(not_thirsty)\"\nexpected=\"Water is essential\"\nif [ \"$out\" != \"$expected\" ]; then\n    echo \"not_thirsty error. Expected '$expected', got '$out'\"\n    exit 1\nfi\nif [ \"$before\" = \"$(cat \"$DRINK_WATER_CONF\")\" ]; then\n    echo \"not_thirsty error. Last drink time was not updated\"\n    exit 1\nfi\n\n# Test that next_drink outputs correctly\nout=\"$(next_drink)\"\nexpected=\"Next drink at $(date --date=\"@$(($(cat \"$DRINK_WATER_CONF\") + \"$WATER_TIME\"))\")\"\nif [ \"$out\" != \"$expected\" ]; then\n    echo \"next_drink error. Expected '$expected', got '$out'\"\n    exit 1\nfi\n\nrm -f \"$DRINK_WATER_CONF\"\necho \"All tests passed\"\n"
  }
]