sleep-tracker
Health and wellness tracker for logging daily activities, tracking streaks, viewing statistics, setting reminders and goals, and getting health tips. A versatile CLI tool for building and maintaining healthy habits.
Commands
| Command | Description |
|---|
| INLINECODE0 | Log a new entry with today's date |
| INLINECODE1 |
Show all entries logged today |
|
sleep-tracker streak | Check your current streak of consecutive days |
|
sleep-tracker stats | Show total number of entries in the data log |
|
sleep-tracker reminder <task> [time] | Set a reminder for a task (default time: 8:00) |
|
sleep-tracker tips | Get health tips (hydration, movement, sleep) |
|
sleep-tracker goal <goal> [frequency] | Set a goal with optional frequency (default: daily) |
|
sleep-tracker history | View the last 14 entries from the data log |
|
sleep-tracker export | Export all data to stdout |
|
sleep-tracker reset | Reset tracker (requires
--confirm flag to actually clear data) |
|
sleep-tracker help | Show help message with all available commands |
|
sleep-tracker version | Show version number |
How It Works
INLINECODE13 manages a simple text-based data log (data.log) where each entry is automatically stamped with the current date. It provides a lightweight way to track health activities, build streaks, and review your history.
Daily Workflow
- 1. Log activities: Record what you did — exercise, meals, sleep times, etc.
- Check today: Review everything logged today with INLINECODE15
- Track progress: Use
streak to see consecutive days and stats for totals - Set goals and reminders: Keep yourself accountable with
goal and INLINECODE19 - Review history: Look at the last 2 weeks with INLINECODE20
Data Storage
All data is stored in $SLEEP_TRACKER_DIR or defaults to ~/.local/share/sleep-tracker/. The directory contains:
- -
data.log — main data file with date-stamped entries - INLINECODE24 — timestamped log of all commands executed for auditing
The tool automatically creates the data directory on first run. You can override the storage location by setting the SLEEP_TRACKER_DIR environment variable.
Requirements
- - Shell: Bash 4+
- No external dependencies — uses only standard Unix utilities (
date, grep, wc, tail, cat) - Works on: Linux, macOS, any POSIX-compatible system
When to Use
- 1. Daily health logging — Run
sleep-tracker log "8h sleep, felt rested" each morning to build a habit history - Tracking exercise streaks — Log workouts daily and check
sleep-tracker streak to stay motivated with consecutive-day tracking - Setting health reminders — Use
sleep-tracker reminder "drink water" 14:00 to record reminder notes for key health tasks - Reviewing weekly patterns — Run
sleep-tracker history to see the last 14 entries and spot trends in your health data - Exporting data for analysis — Use
sleep-tracker export > health-data.txt to get all records into a file for spreadsheet analysis or sharing with a health professional
Examples
CODEBLOCK0
Health Tips (Built-in)
The tips command provides three core health reminders:
- 1. Stay hydrated — drink water throughout the day
- Move every hour — take short breaks from sitting
- Sleep 7-8 hours — prioritize consistent rest
Configuration
Set the SLEEP_TRACKER_DIR environment variable to change the data directory:
CODEBLOCK1
Default location: INLINECODE38
Output
All output goes to stdout in plain text. Use shell redirection to save results:
CODEBLOCK2
Powered by BytesAgain | bytesagain.com | hello@bytesagain.com
sleep-tracker
健康和养生追踪器,用于记录日常活动、追踪连续天数、查看统计数据、设置提醒和目标,以及获取健康小贴士。这是一个多功能命令行工具,帮助建立和维持健康习惯。
命令
| 命令 | 描述 |
|---|
| sleep-tracker log <条目> | 使用今天的日期记录新条目 |
| sleep-tracker today |
显示今天记录的所有条目 |
| sleep-tracker streak | 查看当前连续天数 |
| sleep-tracker stats | 显示数据日志中的条目总数 |
| sleep-tracker reminder <任务> [时间] | 为任务设置提醒(默认时间:8:00) |
| sleep-tracker tips | 获取健康小贴士(补水、运动、睡眠) |
| sleep-tracker goal <目标> [频率] | 设置目标并可选频率(默认:每日) |
| sleep-tracker history | 查看数据日志中最近14条记录 |
| sleep-tracker export | 将所有数据导出到标准输出 |
| sleep-tracker reset | 重置追踪器(需要--confirm标志才能实际清除数据) |
| sleep-tracker help | 显示包含所有可用命令的帮助信息 |
| sleep-tracker version | 显示版本号 |
工作原理
sleep-tracker 管理一个简单的基于文本的数据日志(data.log),每条记录都会自动标记当前日期。它提供了一种轻量级的方式来追踪健康活动、建立连续记录和回顾历史。
日常使用流程
- 1. 记录活动:记录你所做的事情——运动、饮食、睡眠时间等。
- 查看今日:使用 sleep-tracker today 查看今天记录的所有内容
- 追踪进度:使用 streak 查看连续天数,使用 stats 查看总数
- 设置目标和提醒:通过 goal 和 reminder 保持自律
- 回顾历史:使用 history 查看最近两周的记录
数据存储
所有数据存储在 $SLEEPTRACKERDIR 或默认路径 ~/.local/share/sleep-tracker/。该目录包含:
- - data.log — 主要数据文件,包含带日期标记的条目
- history.log — 所有已执行命令的时间戳日志,用于审计
该工具会在首次运行时自动创建数据目录。你可以通过设置 SLEEPTRACKERDIR 环境变量来覆盖存储位置。
系统要求
- - Shell:Bash 4+
- 无外部依赖 — 仅使用标准Unix工具(date、grep、wc、tail、cat)
- 兼容系统:Linux、macOS、任何POSIX兼容系统
使用场景
- 1. 每日健康记录 — 每天早上运行 sleep-tracker log 8小时睡眠,感觉休息充分 来建立习惯历史
- 追踪运动连续天数 — 每天记录锻炼,使用 sleep-tracker streak 通过连续天数追踪保持动力
- 设置健康提醒 — 使用 sleep-tracker reminder 喝水 14:00 为关键健康任务记录提醒
- 回顾周度模式 — 运行 sleep-tracker history 查看最近14条记录,发现健康数据中的趋势
- 导出数据进行分析 — 使用 sleep-tracker export > health-data.txt 将所有记录导出到文件,用于电子表格分析或与健康专业人士分享
示例
bash
记录睡眠条目
sleep-tracker log 睡了7.5小时,质量4/5
记录运动
sleep-tracker log 慢跑30分钟,5公里
记录饮食
sleep-tracker log 健康早餐:燕麦片、水果、咖啡
查看今天记录的内容
sleep-tracker today
查看连续天数
sleep-tracker streak
获取总体统计
sleep-tracker stats
设置每日饮水提醒
sleep-tracker reminder 喝2升水 10:00
设置健身目标
sleep-tracker goal 跑5公里 weekly
获取健康小贴士
sleep-tracker tips
查看最近14条记录
sleep-tracker history
将所有数据导出到文件
sleep-tracker export > my-health-log.txt
重置(试运行 — 显示说明)
sleep-tracker reset
健康小贴士(内置)
tips 命令提供三个核心健康提醒:
- 1. 保持水分 — 全天多喝水
- 每小时活动 — 短暂离开座位休息
- 睡眠7-8小时 — 优先保证规律休息
配置
设置 SLEEPTRACKERDIR 环境变量来更改数据目录:
bash
export SLEEPTRACKERDIR=$HOME/my-health-data
默认位置:~/.local/share/sleep-tracker/
输出
所有输出以纯文本形式输出到标准输出。使用shell重定向保存结果:
bash
sleep-tracker history > weekly-review.txt
sleep-tracker export | grep 2024-03
由 BytesAgain 提供技术支持 | bytesagain.com | hello@bytesagain.com