Skip to content

feat(zsh): add currency conversion support for cost display#2382

Merged
tusharmath merged 6 commits intomainfrom
zsh-cost-convertor
Feb 11, 2026
Merged

feat(zsh): add currency conversion support for cost display#2382
tusharmath merged 6 commits intomainfrom
zsh-cost-convertor

Conversation

@tusharmath
Copy link
Copy Markdown
Collaborator

@tusharmath tusharmath commented Feb 11, 2026

Summary

Add configurable currency conversion support to zsh rprompt cost display, enabling users to view costs in their preferred currency and exchange rate.

Context

The zsh rprompt previously displayed costs only in USD with a hardcoded "$" symbol. Users in different regions needed to mentally convert costs to their local currency, which was inconvenient and error-prone. This change allows users to configure their preferred currency symbol and conversion rate via environment variables.

Changes

  • Added currency_symbol and conversion_ratio fields to ZshRPrompt struct
  • Added environment variable support for FORGE_CURRENCY_SYMBOL (defaults to "$")
  • Added environment variable support for FORGE_CURRENCY_CONVERSION_RATE (defaults to 1.0)
  • Updated cost display logic to apply conversion ratio and use custom currency symbol
  • Added comprehensive tests for currency conversion (INR and EUR examples)

Key Implementation Details

  • Currency configuration is read from environment variables at rprompt initialization
  • Conversion ratio multiplies the base USD cost to get the displayed value
  • Currency symbol can be any string (e.g., "INR", "€", "£", "¥")
  • Backward compatible: defaults to USD with "$" symbol if no configuration provided

Use Cases

  • View costs in INR for Indian users: export FORGE_CURRENCY_SYMBOL=INR FORGE_CURRENCY_CONVERSION_RATE=83.5
  • View costs in EUR for European users: export FORGE_CURRENCY_SYMBOL=€ FORGE_CURRENCY_CONVERSION_RATE=0.92
  • View costs in GBP for UK users: export FORGE_CURRENCY_SYMBOL=£ FORGE_CURRENCY_CONVERSION_RATE=0.79

Testing

# Run unit tests for rprompt
cargo test -p forge_main zsh::rprompt

# Test with custom currency
export FORGE_CURRENCY_SYMBOL=INR
export FORGE_CURRENCY_CONVERSION_RATE=83.5
# Verify rprompt displays converted costs

Links

  • Related files: crates/forge_main/src/zsh/rprompt.rs, crates/forge_main/src/ui.rs

@github-actions github-actions Bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Feb 11, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 11, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ tusharmath
❌ Tushar Mathur
❌ forge-code-agent


Tushar Mathur seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

.conversion_ratio(83.5)
.to_string();

let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.83%f%b %F{134}\u{ec19} gpt-4%f";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test expectation is mathematically incorrect. The calculation 0.01 * 83.5 = 0.835 will round to 0.84 when formatted with {:.2}, not 0.83. This test will fail.

let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.84%f%b %F{134}\u{ec19} gpt-4%f";
Suggested change
let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.83%f%b %F{134}\u{ec19} gpt-4%f";
let expected = " %B%F{15}\u{f167a} FORGE%f%b %B%F{15}1.5k%f%b %B%F{2}INR0.84%f%b %F{134}\u{ec19} gpt-4%f";

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

token_count: None,
cost: None,
use_nerd_font: true,
currency_symbol: "\u{f155}".to_string(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent default currency symbol. The Default impl sets currency_symbol to "\u{f155}" (a Nerd Font icon), but the UI code in ui.rs defaults to "$" when FORGE_CURRENCY_SYMBOL is not set, and all documentation states the default is "$". This creates inconsistent behavior depending on how ZshRPrompt is instantiated.

// Should be:
currency_symbol: "$".to_string(),

This ensures consistency with the documented behavior and the UI code path. The Nerd Font icon \u{f155} should only be used when explicitly configured via the environment variable or builder method.

Suggested change
currency_symbol: "\u{f155}".to_string(),
currency_symbol: "$".to_string(),

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@tusharmath tusharmath merged commit 59c98d2 into main Feb 11, 2026
10 of 11 checks passed
@tusharmath tusharmath deleted the zsh-cost-convertor branch February 11, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants