Skip to content

Instantly share code, notes, and snippets.

@deadflowers
Last active March 19, 2026 23:00
Show Gist options
  • Select an option

  • Save deadflowers/d27f917a721628a16a90fb0b04d5a821 to your computer and use it in GitHub Desktop.

Select an option

Save deadflowers/d27f917a721628a16a90fb0b04d5a821 to your computer and use it in GitHub Desktop.
U.S. Debt Counter

US DEBT TICKER

Terminal dashboard debt counter optimized for Termux in landscape mode. Syncs with U.S. Treasury API (2026-03-18 snapshot) and projects growth at $87,531/sec.


1. Quick Install

Run this one-liner to grab dependencies and the script from this gist in one step:

pkg update && pkg install curl figlet jq bc ncurses-utils -y && \
curl -sL https://gist.githubusercontent.com/deadflowers/d27f917a721628a16a90fb0b04d5a821/raw/usdebt.sh -o usdebt.sh && \
chmod +x usdebt.sh

2. Usage

./usdebt.sh

by Ray Kooyenga

#!/bin/bash
export LC_NUMERIC=en_US.UTF-8
# Snapshot for 2026-03-18
BASE_DEBT=39004964392193
DEBT_PER_SEC=87531
API_URL="https://api.fiscaldata.treasury.gov/services/api/fiscal_service/v2/accounting/od/debt_to_penny?sort=-record_date&limit=1"
# Sync with Treasury
DATA=$(curl -s --connect-timeout 2 "$API_URL")
if [[ $? -eq 0 && -n "$DATA" ]]; then
BASE_DEBT=$(echo "$DATA" | jq -r '.data[0].tot_pub_debt_out_amt')
REC_DATE=$(echo "$DATA" | jq -r '.data[0].record_date')
else
REC_DATE=$(date +%Y-%m-%d)
fi
# Set baseline to the start of the current day for real-time tracking
START_TS=$(date -d "$REC_DATE" +%s)
tput civis
trap "tput cnorm; clear; exit" SIGINT
# Blue header
printf "\e[H\e[J\e[1;34m"
figlet -f slant "US DEBT"
# White byline
CUR_DATE=$(date +%Y-%m-%d)
printf "\e[1;37m%s | \$%s/sec | src: trsry.gov\e[0m\n" "$CUR_DATE"
printf "\e[1;34m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\e[0m\n\n"
# Anchor for ticker
tput sc
while :; do
NOW=$(date +%s%N)
DIFF_NS=$((NOW - (START_TS * 1000000000)))
# Calculate real-time drift
ADDED=$(echo "scale=9; ($DIFF_NS / 1000000000) * $DEBT_PER_SEC" | bc -l)
TOTAL=$(echo "$BASE_DEBT + $ADDED" | bc -l | cut -d'.' -f1)
printf -v VAL "%'d" "$TOTAL"
# Red Counter
tput rc
printf " \e[1;31m\$%s\e[0m" "$VAL"
sleep 0.03
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment