Repository navigation
Add unirate-currency-converter package #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # UniRate Currency Converter | ||
|
|
||
| Convert amounts and look up live exchange rates without leaving whatever you're | ||
| typing in. Powered by the [UniRate API](https://unirateapi.com) via the small, | ||
| zero-dependency [`unirate` CLI](https://github.com/UniRate-API/unirate-cli). | ||
|
|
||
| ## Triggers | ||
|
|
||
| | Trigger | What it does | Example output | | ||
| |---|---|---| | ||
| | `:fx` | Opens a form (amount / from / to) and converts | `100 USD = 92.5 EUR` | | ||
| | `:rate` | Opens a form (from / to) and returns the unit rate | `1 USD = 150 JPY` | | ||
|
|
||
| Currency codes are the usual ISO-4217 codes (`USD`, `EUR`, `JPY`, `GBP`, …); | ||
| 170+ fiat and crypto currencies are supported. | ||
|
|
||
| ## Setup | ||
|
|
||
| This package shells out to the `unirate` CLI, so you need two things: | ||
|
|
||
| 1. **Install the CLI** — pick one: | ||
|
|
||
| ```bash | ||
| # macOS (Homebrew) | ||
| brew install --cask UniRate-API/unirate/unirate | ||
|
|
||
| # Windows (Scoop) | ||
| scoop bucket add unirate https://github.com/UniRate-API/scoop-unirate | ||
| scoop install unirate | ||
|
|
||
| # Any platform with a Go toolchain | ||
| go install github.com/UniRate-API/unirate-cli@latest | ||
| ``` | ||
|
|
||
| Prebuilt binaries for linux/macOS/windows are also attached to each | ||
| [GitHub release](https://github.com/UniRate-API/unirate-cli/releases). | ||
|
|
||
| 2. **Set a free API key** — [get one here](https://unirateapi.com) (no credit | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unirate website looks horrible - I tried two browsers - which doesn't inspire confidence! Perhaps take people directly to the registration page at https://unirateapi.com/register, please? |
||
| card), then export it so espanso's shell commands can see it: | ||
|
|
||
| ```bash | ||
| export UNIRATE_API_KEY="your-api-key" | ||
| ``` | ||
|
|
||
| Put that line in your shell profile (`~/.bashrc`, `~/.zshrc`, or the Windows | ||
| equivalent) and restart espanso so it inherits the variable. | ||
|
|
||
| Verify the CLI works on its own first: | ||
|
|
||
| ```bash | ||
| unirate convert 100 USD EUR | ||
| # 100 USD = 92.5 EUR | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - Both triggers are **read-only** — they make an HTTPS GET to the UniRate API | ||
| and print the result. Nothing is written to or changed on your system. | ||
| - If a trigger expands to nothing, the CLI probably isn't on espanso's PATH or | ||
| `UNIRATE_API_KEY` isn't set in the environment espanso was launched from. | ||
|
|
||
| ## License | ||
|
|
||
| MIT — see the [`unirate-cli` repository](https://github.com/UniRate-API/unirate-cli). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: "unirate-currency-converter" | ||
| title: "UniRate Currency Converter" | ||
| description: "Convert amounts and look up live exchange rates inline, powered by the UniRate API command-line client." | ||
| version: 0.1.0 | ||
| author: UniRate API | ||
| homepage: "https://github.com/UniRate-API/unirate-cli" | ||
| tags: ["currency", "exchange-rate", "forex", "money", "converter", "finance", "unirate"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # UniRate Currency Converter | ||
| # | ||
| # Requires the `unirate` CLI on your PATH and a free UNIRATE_API_KEY in your | ||
| # environment. See the README for setup. Both commands are read-only HTTPS GETs | ||
| # against the UniRate API — they never write to or modify the system. | ||
|
|
||
| matches: | ||
| # Convert an amount between two currencies. | ||
| # :fx -> form (amount / from / to) -> e.g. "100 USD = 92.5 EUR" | ||
| - trigger: ":fx" | ||
| replace: "{{result}}" | ||
| vars: | ||
| - name: form | ||
| type: form | ||
| params: | ||
| layout: "Convert [[amount]] [[from]] into [[to]]" | ||
| fields: | ||
| amount: | ||
| default: "100" | ||
| from: | ||
| default: "USD" | ||
| to: | ||
| default: "EUR" | ||
| - name: result | ||
| type: shell | ||
| params: | ||
| cmd: "unirate convert {{form.amount}} {{form.from}} {{form.to}}" | ||
| trim: true | ||
|
Comment on lines
+25
to
+28
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not overly concerned about this - the package only acts upon user-entered data, although there's a non-zero risk of pasting unsanitised text into the form. Use of the above suggestion or quoted "$ESPANSO_ENVIRONMENT_VARIABLES" would reduce the risk of command injection, however. |
||
|
|
||
| # Look up the live rate for a single currency pair. | ||
| # :rate -> form (from / to) -> e.g. "1 USD = 150 JPY" | ||
| - trigger: ":rate" | ||
| replace: "{{result}}" | ||
| vars: | ||
| - name: form | ||
| type: form | ||
| params: | ||
| layout: "Exchange rate: 1 [[from]] in [[to]]" | ||
| fields: | ||
| from: | ||
| default: "USD" | ||
| to: | ||
| default: "EUR" | ||
| - name: result | ||
| type: shell | ||
| params: | ||
| cmd: "unirate rate {{form.from}} {{form.to}}" | ||
| trim: true | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a little clearer. I had to follow the link to see what you meant. Perhaps change to:
"Prebuilt
uniratebinaries for Linux, macOS & Windows are available at the project's Release page."