qn
Shell-aware command completion notifications.
qn wraps shell commands and sends a completion notification — exit code, duration, working directory, and optionally stdout/stderr — to a configurable HTTP endpoint. Pair it with QQ Task Notifier to get push notifications in QQ when long-running tasks finish.
Installation
Prebuilt binaries are not yet provided; cargo install builds from source.
Quick start
# One-time setup — configure endpoint, token, and device name
# Wrap any command
After the command finishes, qn sends a notification like:
my-server
任务完成
命令:make -j12
退出码:0
耗时:2m 15s
工作目录:/home/me/project
Shell integration
Shell integration makes qn a transparent wrapper: wrap commands with qn instead of remembering flags, and get notifications automatically. Long-running commands (≥30s) are detected; short ones skip the notification.
# Install for your shell (auto-detected)
This appends a shell function to your rc file. After restarting your shell or sourcing the rc file:
# Just prefix any command with qn
To print the shell function without modifying rc files (e.g. for plugin managers):
Usage
qn [-a|--attach-output] [--no-notify] <command> [args...]
qn [-a|--attach-output] [--no-notify] --shell <command-string>
qn init
qn shell-init <fish|bash|zsh>
qn init-shell <fish|bash|zsh>
| Flag | Effect |
|---|---|
-a, --attach-output |
Include stdout and stderr in the notification |
--no-notify |
Run the command but skip the notification |
Configuration
qn init walks through setup interactively:
- Device name — identifies this machine in notifications (defaults to hostname).
- Endpoint URL — where to POST the notification. Default:
https://krust.iepose.cn/task-completed, which is the QQ Task Notifier API. - Token — Bearer token for the endpoint.
All values are stored in ~/.config/qn/config and can also be set via environment variables:
| Env var | Config key | Description |
|---|---|---|
QN_ENDPOINT |
endpoint |
Notification API URL |
QN_TOKEN |
token |
Bearer token |
Environment variables take precedence over the config file.
Server-side: QQ Task Notifier
qn sends notifications to any HTTP endpoint that accepts:
POST /task-completed
Authorization: Bearer <token>
Content-Type: application/json
{"summary": "device-name\n..."}
The companion QQ Task Notifier provides this endpoint and forwards messages to QQ private chat. Deploy it alongside qn for push notifications on your phone.
Quick server setup:
# Edit docker-compose.yml with your QQ Bot credentials
Then configure qn to point at the server:
How it works
qnspawns the requested command as a child process.- When the command exits, it captures the exit code, elapsed time, and optionally stdout/stderr.
- It POSTs a JSON summary to the configured endpoint.
- The server (e.g. QQ Task Notifier) delivers the notification to your messaging platform.
Shell integration uses a shell function that intercepts qn <command> calls: the function runs the command, then calls qn __notify with the exit code and timing to send the notification without a second HTTP round-trip for command execution.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.