Skip to content

Optional configuration override for taskwarrior filters #2174

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

Merged
merged 1 commit into from
Aug 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/blocks/taskwarrior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@
//! `interval` | Update interval in seconds | `600` (10min)
//! `warning_threshold` | The threshold of pending (or started) tasks when the block turns into a warning state | `10`
//! `critical_threshold` | The threshold of pending (or started) tasks when the block turns into a critical state | `20`
//! `filters` | A list of tables with the keys `name` and `filter`. `filter` specifies the criteria that must be met for a task to be counted towards this filter. | ```[{name = "pending", filter = "-COMPLETED -DELETED"}]```
//! `filters` | A list of tables describing filters (see bellow) | ```[{name = "pending", filter = "-COMPLETED -DELETED"}]```
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $count.eng(w:1) "`
//! `format_singular` | Same as `format` but for when exactly one task is pending. | `" $icon $count.eng(w:1) "`
//! `format_everything_done` | Same as `format` but for when all tasks are completed. | `" $icon $count.eng(w:1) "`
//! `data_location`| Directory in which taskwarrior stores its data files. Supports path expansions e.g. `~`. | `"~/.task"`
//!
//! ## Filter configuration
//!
//! Key | Values | Default
//! ----|--------|--------
//! `name` | The name of the filter |
//! `filter` | Specifies the criteria that must be met for a task to be counted towards this filter |
//! `config_override` | An array containing configuration overrides, useful for explicitly setting context or other configuration variables | `[]`
//!
//! # Placeholders
//!
//! Placeholder | Value | Type | Unit
//! --------------|---------------------------------------------|--------|-----
//! `icon` | A static icon | Icon | -
//! `count` | The number of tasks matching current filter | Number | -
//! `filter_name` | The name of current filter | Text | -
//!
//! # Actions
//!
//! Action | Default button
//! --------------|---------------
//! `next_filter` | Right
Expand All @@ -44,6 +56,7 @@
//! [[block.filters]]
//! name = "some-project"
//! filter = "project:some-project +PENDING"
//! config_override = ["rc.context:none"]
//! ```
//!
//! # Icons Used
Expand Down Expand Up @@ -75,6 +88,7 @@ impl Default for Config {
filters: vec![Filter {
name: "pending".into(),
filter: "-COMPLETED -DELETED".into(),
config_override: Default::default(),
}],
format: default(),
format_singular: default(),
Expand Down Expand Up @@ -109,7 +123,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
.error("Failed to create event stream")?;

loop {
let number_of_tasks = get_number_of_tasks(&filter.filter).await?;
let number_of_tasks = get_number_of_tasks(filter).await?;

let mut widget = Widget::new();

Expand Down Expand Up @@ -147,9 +161,14 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
}
}

async fn get_number_of_tasks(filter: &str) -> Result<u32> {
async fn get_number_of_tasks(filter: &Filter) -> Result<u32> {
let args_iter = filter.config_override.iter().map(String::as_str).chain([
"rc.gc=off",
&filter.filter,
"count",
]);
let output = Command::new("task")
.args(["rc.gc=off", filter, "count"])
.args(args_iter)
.output()
.await
.error("failed to run taskwarrior for getting the number of tasks")?
Expand All @@ -166,4 +185,6 @@ async fn get_number_of_tasks(filter: &str) -> Result<u32> {
pub struct Filter {
pub name: String,
pub filter: String,
#[serde(default)]
pub config_override: Vec<String>,
}