npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nightscout-ps1-daemon

v2.1.1

Published

Syncs the latest blood glucose reading from Nightscout to an ini file

Downloads

4

Readme

nightscout-ps1-daemon

Periodically syncs the latest entry from Nightscout to a source-able file, so that you can include your latest blood glucose entry in your terminal prompt (also known as the $PS1 variable).

The trend and target high/low values are also provided, so that you may render arrows and colors as desired:

Installation

Preferred installation is by downloading a pre-compiled binary for your platform:

If there is no binary for your platform, or you would simply like to install from source, do so from npm:

$ npm install -g nightscout-ps1-daemon

Configure your $PS1

As a programmer, your $PS1 is a highly intimate thing which you should take some time to create a setup that is pleasing to you. After all, you are staring at it all day. That said, how you use the nightscout-ps1 variables is up to you! However, for convenience, the setup from the screenshots above is included here as well. OK, on to the technical stuff.

The main key is to source the ~/.bgl-cache file in a function which gets executed in the $PS1. The cache file looks something like:

local nightscout_ts="1513457266000"
local nightscout_bgl="104"
local nightscout_trend="FortyFiveDown"
local nightscout_target_top="180"
local nightscout_target_bottom="80"
local nightscout_mgdl="104"
local nightscout_mills="1513457266000"
local nightscout_device="share2"
local nightscout_direction="FortyFiveDown"
local nightscout_scaled="104"

To achieve a setup similar to the screenshots above, include the code below as a starting point. Typically you define your $PS1 in your .bashrc, .profile, or other similar files that get executed every time a shell session is started.

RED="$(tput setaf 1 2>/dev/null || echo '')"
GREEN="$(tput setaf 2 2>/dev/null || echo '')"
YELLOW="$(tput setaf 3 2>/dev/null || echo '')"
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"

function __ps1_bgl {
  source ~/.bgl-cache

  local trend="?"
  case "${nightscout_trend}" in
    DoubleUp) trend="⇈";;
    SingleUp) trend="↑";;
    FortyFiveUp) trend="↗";;
    Flat) trend="→";;
    FortyFiveDown) trend="↘";;
    SingleDown) trend="↓";;
    DoubleDown) trend="⇊";;
  esac

  if [ "${nightscout_bgl}" -ge "${nightscout_target_top}" ]; then
    printf "\001${YELLOW}\002"
  elif [ "${nightscout_bgl}" -le "${nightscout_target_bottom}" ]; then
    printf "\001${RED}\002"
  else
    printf "\001${GREEN}\002"
  fi
  printf "%03d %s" "${nightscout_bgl}" "${trend}"
  printf "\001${NO_COLOR}\002"
}

export PS1="\$(__ps1_bgl) $ "

Remember to customize the $PS1 further as you like! Restart your shell session, or source the file again to see the changes in effect.

Setup on macOS

cp service/io.n8.nightscout-ps1.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/io.n8.nightscout-ps1.plist

Setup on Linux

cp service/nightscout-ps1.service /etc/systemd/system/
sudo systemd start nightscout-ps1
sudo systemd enable nightscout-ps1

Setup on Windows

Check out this blog post by Scott Hanselman to setup as a Windows Service: