DEV Community

Stephano Kambeta
Stephano Kambeta

Posted on

Project: Build a Terminal-Based Habit Tracker in Termux

Real talk. You want a habit tracker that lives in Termux, runs on your phone, and does not rely on fancy apps or cloud subscriptions. You want something fast, private, and simple to use from the command line. Good. This guide walks you through a working, beginner-friendly habit tracker you can build in Termux today. I will show you the idea, the code, how to run it, and how to secure and expand it if you want to level up later.

Why a terminal habit tracker?

  • It is lightweight and private. Your data stays on your device unless you choose to sync it.
  • It teaches you automation basics you can reuse for other Termux projects. See Quick Termux projects you can do for starter ideas.
  • It is scriptable. Once you have your tracker, you can add notifications, backups, and integrations with tools like ngrok or simple web front ends like the Termux Nginx guide.

Plan for the project

  1. Install Termux and necessary packages. See How to install Termux on Android phone if you need setup help.
  2. Create a CSV-based data file to store daily entries.
  3. Write a simple shell script to log habits and show reports.
  4. Add small improvements: weekly summary, backup, privacy tips.

What the tracker does

The tracker will let you:

  • Add one or more habits (name them once).
  • Mark a habit done for today.
  • Show a simple report: streaks, completion rate for the last 7 and 30 days.
  • Export CSV for spreadsheets or backup.

Install packages

Open Termux and run:

pkg update && pkg upgrade -y
pkg install bash coreutils grep dateutils awk sed git -y

If you prefer a Python version later, install python with pkg install python. For now the bash version is small and works everywhere.

Project structure

~/habit-tracker/
habit-tracker.sh
habits.csv
habits-list.txt

Create the folder and files:

mkdir -p ~/habit-tracker
cd ~/habit-tracker
touch habit-tracker.sh habits.csv habits-list.txt
chmod +x habit-tracker.sh

habits.csv format

We will store rows like:

date,habit,status
2025-10-01,read,1
2025-10-01,exercise,0

Where status is 1 for done and 0 for not done. You can open the CSV in a spreadsheet if you want to visualize data later.

Minimal habit-tracker.sh (copy and paste)

#!/usr/bin/env bash
DATA="$HOME/habit-tracker/habits.csv"
LIST="$HOME/habit-tracker/habits-list.txt"
mkdir -p "$(dirname "$DATA")"
if [ ! -f "$DATA" ]; then
  echo "date,habit,status" > "$DATA"
fi
today=$(date +%F)

function add_habit() {
  read -p "Enter habit name: " name
  echo "$name" >> "$LIST"
  sort -u "$LIST" -o "$LIST"
  echo "Added habit: $name"
}

function list_habits() {
  nl -ba "$LIST"
}

function mark_done() {
  echo "Select a habit to mark done:"
  list_habits
  read -p "Enter number: " n
  habit=$(sed -n "${n}p" "$LIST")
  if [ -z "$habit" ]; then
    echo "Invalid choice"
    return
  fi
  # Remove existing entry for today+habit
  grep -v "^$today,$habit," "$DATA" > "$DATA.tmp" || true
  mv "$DATA.tmp" "$DATA"
  echo "$today,$habit,1" >> "$DATA"
  echo "Marked $habit as done for $today"
}

function show_report() {
  read -p "Show report for how many days? (7/30): " days
  if ! [[ "$days" =~ ^[0-9]+$ ]]; then days=7; fi
  since=$(date -d "$days days ago" +%F 2>/dev/null || date -v-"$days"d +%F)
  echo "Report since $since"
  awk -F, -v start="$since" 'NR>1 && $1>=start {count[$2]++; done[$2]+=$3}
  END{
    for(h in count){
      pct = (done[h]/count[h])*100
      printf "%-20s %4d/%-4d %6.2f%%\n", h, done[h], count[h], pct
    }
  }' "$DATA"
}

function export_csv() {
  cp "$DATA" "$HOME/habit-tracker/habits-export-$(date +%F).csv"
  echo "Exported to ~/habit-tracker/"
}

PS3="Choose an option: "
options=("Add habit" "Mark done" "List habits" "Show report" "Export CSV" "Exit")
select opt in "${options[@]}"; do
  case $opt in
    "Add habit") add_habit ;;
    "Mark done") mark_done ;;
    "List habits") list_habits ;;
    "Show report") show_report ;;
    "Export CSV") export_csv ;;
    "Exit") break ;;
    *) echo "Invalid option $REPLY" ;;
  esac
done

This is small and opinionated on purpose. It uses a plain text list for habit names and a CSV for entries. The report shows completion rate for the chosen window.

How to use it

  1. Run ~/habit-tracker/habit-tracker.sh.
  2. Choose Add habit and add things like read, exercise, meditate.
  3. Every time you do one, run the script and choose Mark done.
  4. Use Show report to check progress over the last 7 or 30 days.

Automate daily check-in

If you want a reminder each morning, Termux can send a simple notification with termux-notification but that requires the Termux:API add-on. If you prefer a minimal approach, add an alias or place a launcher shortcut to run the script. For power users, you can use termux-job-scheduler to schedule a daily notification.

Security and privacy pain points

Storing habits on your phone is private by default, but if you choose to sync or export, consider these points:

If you are using Termux to learn offensive security tools, remember to separate learning environments from your daily phone data. You can read about ethical boundaries and tools in my write ups like MaxPhisher in Termux and other guides. Operational security matters. See Operational security simple guide for more.

Backups and exports

Simple export is already in the script. For periodic backups you can:

  • Push CSV to a private git repo on your own server or on a private hosted provider. Use git init and commit the export file. If you do this, do not push to public repositories.
  • Encrypt before syncing. Use gpg to encrypt CSVs before upload.
  • If you want automatic cloud backup, create a script that encrypts the CSV and uploads with tools supported in Termux. If you are unsure how to do that safely, read the security planning articles linked above and consider professional guidance. See cyber security for small companies for higher level advice.

Extending the tracker

Here are ideas to grow the project from a simple script into a useful toolchain.

  • Convert to Python for richer stats and nicer output. Python makes plotting and streak calculations easier.
  • Add a web UI served by a lightweight flask app and Nginx. If you decide to expose a web server, read the Termux Nginx guide first.
  • Integrate with notification systems. Termux has API hooks for notifications and shortcuts.
  • Track time spent on tasks by logging start and stop timestamps. This becomes a very small time tracker.
  • Integrate secure sync only when you understand the risks. If you run a small business and plan to scale automation, see how NIST guidance maps to business risk in how NISTIR 8286 connects cybersecurity and business risk.

Common problems and fixes

Problem Fix
Script errors on a fresh Termux install Run pkg install coreutils bash grep and ensure habit-tracker.sh is executable
Date commands fail on some Android setups Use the alternative date fallback provided in the script or install busybox if needed
Confused about privacy when testing network tools Separate test environment. Read cyber attacks simple guide and operational security notes before experimenting

Examples of how people use this

My readers use this tracker to:

  • Log daily study time and measure consistency during exam prep.
  • Track short habits like water intake or planning the day.
  • Combine with other Termux experiments, for example automating a daily export and emailing it to yourself with a secure script. If you automate emailing or remote access, read about secure remote access tools and risks first.

Where to go next

If you loved this and want more Termux projects, check quick Termux projects you can do. If you want to harden your phone and connections before you start doing networked projects, read VPNs to use when using Termux and my review Surfshark VPN review.

For readers working in small businesses who want to make tool choices and plans that protect their operations, my posts on incident response and security planning are a next step: best cyber incident response companies, cyber security for small companies, and internet security companies.

Final notes

This project is designed to be practical and expandable. Start small, get daily wins, and then automate only the parts you understand. If you run into friction or want the Python version or a small web UI, drop the code you have and I will help you convert it. Keep things private and simple until you know how syncing and servers change your threat model.

If you enjoyed this project, check other Termux guides on the blog. Build, learn, and keep your phone tidy and secure while you experiment.

— Stephano

Top comments (0)