Skip to content

Add live-tennis-scores package - #238

Open
bensynapse wants to merge 4 commits into
espanso:mainfrom
bensynapse:add-live-tennis-scores
Open

Add live-tennis-scores package#238
bensynapse wants to merge 4 commits into
espanso:mainfrom
bensynapse:add-live-tennis-scores

Conversation

@bensynapse

Copy link
Copy Markdown

What it does

Adds live-tennis-scores (0.1.0): typing :tennis expands to a compact one-line summary of the tennis matches live right now — up to 3 matches, player names + per-set games, * on the set in play:

Carlos Alcaraz 6-4 3-2* vs Jannik Sinner · Coco Gauff 2-6 1-1* vs Iga Swiatek

Keyed API — graceful when unset

Unlike dadjoke/cht, the API behind this package needs a key (free tier: 30 req/min, 100 req/day at livetennisapi.com/subscribe/free — far more than a text-expansion trigger uses). Two things keep that from hurting users:

  • No key set → the trigger still expands, to a setup hint: Set LIVETENNIS_API_KEY — free key: livetennisapi.com/subscribe/free. It never fails silently.
  • Bad key / API error → expands to the API's error string (e.g. Live Tennis API error: unauthorized).

The README documents the env-var setup for Linux and macOS (including the GUI-app launchctl setenv caveat).

Transparency (for review)

The entire behavior is one readable pipeline in package.yml — no scripts, no files touched, nothing downloaded and executed:

  • curl -s -H "Authorization: Bearer $LIVETENNIS_API_KEY" "https://api.livetennisapi.com/api/public/v1/matches?status=live&limit=3"
  • grep -o keeps only the player name fields and per-set games arrays (plus any error string)
  • a short awk program pairs them into 6-4 3-2* lines

Only POSIX tools (curl, grep, awk, sh) — no jq dependency, matching the sed/grep style of existing curl packages (no, jops). Tested on gawk, mawk and busybox awk against a canned fixture and against the real endpoint's 401 path; not tested on Windows (README says so, like dadjoke).

.github/scripts/validate passes locally on the package (0 errors).

Disclosure

I maintain the API this package calls (Live Tennis API).

🤖 Generated with Claude Code

:tennis expands to a one-line summary of live tennis matches
(names + per-set games) via a plain curl | grep | awk pipeline
against the Live Tennis API. Requires a free LIVETENNIS_API_KEY;
expands to a setup hint when the key is not set.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@smeech smeech left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm away at the moment so I'll let Copilot do its stuff and run the automated checks.
I note that it should run under WSL. Does that require a shell: addition to the code?

Copilot AI left a comment

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.

Pull request overview

Adds a new Espanso Hub package, live-tennis-scores (v0.1.0), which expands :tennis into a compact one-line summary of up to 3 currently live tennis matches by calling the Live Tennis API and formatting results via a shell pipeline.

Changes:

  • Adds the :tennis trigger implementation in package.yml using curl | grep | awk, with basic handling for missing API key and API-provided error responses.
  • Adds end-user documentation covering installation, API key setup, and a transparency note explaining the pipeline.
  • Adds package metadata (_manifest.yml) and MIT license file for the new package.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/live-tennis-scores/0.1.0/package.yml Implements the :tennis trigger and the fetch/parse/format pipeline.
packages/live-tennis-scores/0.1.0/README.md Documents usage, API key setup, and how the pipeline works.
packages/live-tennis-scores/0.1.0/_manifest.yml Adds Hub metadata (name/title/description/tags/homepage).
packages/live-tennis-scores/0.1.0/LICENSE Adds MIT license text for the package.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +22 to +36
curl -s -H "Authorization: Bearer $LIVETENNIS_API_KEY" "https://api.livetennisapi.com/api/public/v1/matches?status=live&limit=3" \
| grep -o '"error":"[^"]*"\|"name":"[^"]*"\|"score":null\|"games":\[\[[0-9,]*\],\[[0-9,]*\]\]' \
| awk -F'"' '
/"error"/ { print "Live Tennis API error: " $4; err = 1; exit }
/"name"/ { n[++i] = $4 }
/"score":null/ { o = o (o ? " · " : "") n[1] " vs " n[2]; i = 0 }
/"games"/ {
g = $0; sub(/^"games":\[\[/, "", g); sub(/\]\]$/, "", g)
split(g, a, "\\],\\["); m = split(a[1], p, ","); split(a[2], q, ",")
s = ""
for (k = 1; k <= m; k++) if (p[k] != "") s = s " " p[k] "-" q[k]
if (s != "") s = s "*"
o = o (o ? " · " : "") n[1] s " vs " n[2]; i = 0
}
END { if (!err) print (o ? o : "No live matches right now") }'
Comment on lines +64 to +66
- `curl` (plus POSIX `grep`/`awk`/`sh`, preinstalled on Linux and macOS)
- Not tested on Windows (the pipeline assumes a POSIX shell; under WSL it
works)
… WSLENV)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bensynapse

Copy link
Copy Markdown
Author

Good question — the answer is "yes, but only as a documented local edit, not in the package itself."

Espanso's shell: wsl value exists and does exactly what you'd want, but it's a Windows-only accepted value (Windows accepts cmd/powershell/pwsh/wsl/nu; macOS/Linux accept sh/bash/pwsh/nu), and there's no per-OS conditional inside one package — so shipping shell: wsl in package.yml would fix Windows and break Linux/macOS, which keep the POSIX default that already works.

Two things are actually needed on Windows, and I've just pushed a commit (fe8c33f) documenting both in the package README:

  1. shell: wsl added locally under the variable's params:.
  2. The env var made visible inside WSL — a Windows-side LIVETENNIS_API_KEY doesn't cross the boundary on its own; either export it in the WSL profile or forward it with WSLENV (setx WSLENV LIVETENNIS_API_KEY/u).

The README's old "under WSL it works" line understated that, so it now carries the exact two-step recipe instead. Happy to adjust further if you'd prefer Windows handled differently.

@smeech

smeech commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

I'm not sure the addition of shell. wsl will break anything in Linux and MacOS - Espanso should ignore it. I'll test this whenI return home next week. I'd be happy just to see it as a mention in README. md, anyway.

@bensynapse

Copy link
Copy Markdown
Author

No rush at all — and the README already carries it as of fe8c33f (the "Windows (via WSL)" section documents both the shell: wsl edit and the WSLENV forwarding). If your test next week shows Linux/macOS do silently ignore shell: wsl, shipping it directly in package.yml would indeed be even simpler — happy either way.

description: Type :tennis to expand a one-line summary of live tennis matches (via the Live Tennis API, free key required)
version: 0.1.0
author: Live Tennis API
homepage: "https://livetennisapi.com"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This ought to link to a homepage of your own, although it's not critical.


The pipeline assumes a POSIX shell, and espanso's default shell on Windows is
PowerShell — so out of the box the trigger does not work on Windows. Espanso
can route a shell variable through WSL, but `shell: wsl` is a Windows-only

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've checked on Linux, and the presence of shell: wsl has no ill effect. I suggest you add it to the code in package.yml, and amend the README.md accordingly.

vars:
- name: live_scores
type: shell
params:

@smeech smeech Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add shell: wsl here.
See above.

…WSL on Windows

Signed-off-by: Ben Abulafia <ben@synapsereality.io>
@bensynapse

Copy link
Copy Markdown
Author

Good question — yes, it does, and I've pushed the change.

The :tennis expansion is a POSIX pipeline (if [ -z … ], curl | grep | awk), and espanso's shell var defaults to PowerShell on Windows, which won't run it. So I added an explicit shell: bash to the shell var:

    vars:
      - name: live_scores
        type: shell
        params:
          shell: bash
          cmd: |

On macOS/Linux bash is native; on Windows espanso resolves bash to the WSL bash shim, so it runs under WSL exactly as you flagged. (shell: wsl would also work on Windows, but it isn't a valid value on macOS/Linux, so bash is the portable single setting that keeps the same package working on all three.)

Nothing else in the package changed. Thanks for the catch.

@smeech

smeech commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

As long as you've tested shell: bash in Windows and confirmed it works (DeepWiki agrees) then that's fine. According to the documentation it's not a valid option, so I need to update the docs! As I said, shell: wsl would also be fine as Linux, and presumably macOS, ignore it anyway.

Would you like to amend the README.md Windows section a little as package.yml no longer needs editing? It's just that WSL needs to be installed and there's the environment variable bit.

Otherwise we'll be good to merge.

…ips in the package

Signed-off-by: Ben Abulafia <ben@synapsereality.io>
@bensynapse

Copy link
Copy Markdown
Author

Done — amended the README's Windows section.

Since shell: bash now ships in package.yml (espanso routes it through WSL on Windows), the old "edit package.yml yourself" steps are gone. The Windows section now just covers what actually remains: install WSL with a distro that has curl, and make LIVETENNIS_API_KEY visible inside WSL (either export it in the WSL profile or forward it with WSLENV). Linux/macOS run bash natively, so nothing extra there.

Confirmed shell: bash works on Windows via WSL (and, as you noted, Linux/macOS treat bash as the native shell, so it's the one portable value). Thanks for flagging the docs issue on your side too — should be good to merge now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants