Building a Habit Tracker CLI App in Termux

Hey Guys, it's me Saad 🙋🏻‍♂️, How is geek life going? So I was trying to create a habit tracker in Termux and decided to write a script so every time I open my term marks, I will be able to track my programming stuff and analyse some data about myself. Collect them in a folder and then process them to be better. It is just basic Python. If you want to learn more about Python, you can check out article I have written on it.

It is just basic Python. If you want to learn more about Python, you can check out article I have written on it. If U can write better quote than this, write the script, put it in the comments and I will share it with the community with your name on it.

Here we are using Jason to collect the data in a file so you can actually use this to track your habits. Use it and let me know if we can do some improvement in it like AI, adding AI.


What You’ll Learn

  • Create a local habit tracker with Python
  • Save your data in JSON
  • Mark habits as complete each day
  • Show habit streaks + progress
  • Make it your DAILY terminal ritual


How to install and use the Script

Step 1: Install Termux Essentials 

pkg update && pkg upgrade

pkg install python

pkg install nano

Pro tip: You can also use vim or micro instead of nano if you're fancy.


Step 2: Create Your Habit Tracker Script 

Run this in Termux:

nano habit-tracker.py

Then copy-paste this beauty inside

import json

import os

from datetime import date

FILE = "habits.json"

def load_habits():

    if os.path.exists(FILE):

        with open(FILE, "r") as f:

            return json.load(f)

    return {}

def save_habits(habits):

    with open(FILE, "w") as f:

        json.dump(habits, f, indent=2)

def mark_habit(habits):

    today = str(date.today())

    print("\nYour Habits:")

    for idx, habit in enumerate(habits.keys(), 1):

        print(f"{idx}. {habit}")

    choice = int(input("\nWhich habit did you complete today? (number): "))

    habit = list(habits.keys())[choice - 1]

    habits[habit].append(today)

    print(f"✅ Marked '{habit}' for {today}!")

def view_progress(habits):

    for habit, dates in habits.items():

        print(f"\n📌 {habit} — {len(set(dates))} days tracked")

def main():

    habits = load_habits()

    while True:

        print("\n1️⃣ Add Habit\n2️⃣ Mark as Done\n3️⃣ View Progress\n4️⃣ Exit")

        choice = input("Enter choice: ")

        if choice == "1":

            new_habit = input("Enter new habit: ")

            habits[new_habit] = []

            print(f"🎯 Added new habit: {new_habit}")

        elif choice == "2":

            mark_habit(habits)

        elif choice == "3":

            view_progress(habits)

        elif choice == "4":

            break

        else:

            print("⚠️ Invalid option")

        save_habits(habits)

if __name__ == "__main__":

    main()

Tip: You can always reset by deleting the habits.json file


Step 3: Run It Like a Ritual 

python habit-tracker.py

Start by adding your daily habits like "Read 5 pages", "Drink 2L water", "Meditate" etc 🧘‍♂️💧📚

Then mark them daily — super satisfying trust me 



Make it Cooler with Aliases

Add this to your .bashrc or .zshrc 

alias habits="python ~/habit-tracker.py"

Now just type habits every day in your Termux to stay on track 



Some Spicy Add-On Ideas

  • Add colors with termcolor
  • Push Termux notifications with termux-notification
  • Auto sync with Git to back up your JSON
  • Show progress with bar charts using tqdm or rich

[Lemme know if you want a part 2 with voice-based tracking]



Wanna Show Off Your Habits?

Also check the cool courses and hacks on 👉 course.learntermux.tech



Final Thoughts

This is nothing more than a simple python script project that I worked on just so that you guys have some information on how are you can use stomThis is nothing more than a simple python script project that I worked on just so that you guys have some information on how are you can use termux differently. Guys, we need to start creating small applications in Tama show that we have a lot of tools ready to use with more. Is just share them with me and I will give you a shout out here. Thanks for reading. And as always stay ethical.

Post a Comment

0 Comments

⚡ Get Complete Termux Course