Skip to content

Commit 291e4a0

Browse files
myasbim9262
authored andcommitted
Optional configuration override for taskwarrior filters
1 parent c8389be commit 291e4a0

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/blocks/taskwarrior.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,30 @@
99
//! `interval` | Update interval in seconds | `600` (10min)
1010
//! `warning_threshold` | The threshold of pending (or started) tasks when the block turns into a warning state | `10`
1111
//! `critical_threshold` | The threshold of pending (or started) tasks when the block turns into a critical state | `20`
12-
//! `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"}]```
12+
//! `filters` | A list of tables describing filters (see bellow) | ```[{name = "pending", filter = "-COMPLETED -DELETED"}]```
1313
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $count.eng(w:1) "`
1414
//! `format_singular` | Same as `format` but for when exactly one task is pending. | `" $icon $count.eng(w:1) "`
1515
//! `format_everything_done` | Same as `format` but for when all tasks are completed. | `" $icon $count.eng(w:1) "`
1616
//! `data_location`| Directory in which taskwarrior stores its data files. Supports path expansions e.g. `~`. | `"~/.task"`
1717
//!
18+
//! ## Filter configuration
19+
//!
20+
//! Key | Values | Default
21+
//! ----|--------|--------
22+
//! `name` | The name of the filter |
23+
//! `filter` | Specifies the criteria that must be met for a task to be counted towards this filter |
24+
//! `config_override` | An array containing configuration overrides, useful for explicitly setting context or other configuration variables | `[]`
25+
//!
26+
//! # Placeholders
27+
//!
1828
//! Placeholder | Value | Type | Unit
1929
//! --------------|---------------------------------------------|--------|-----
2030
//! `icon` | A static icon | Icon | -
2131
//! `count` | The number of tasks matching current filter | Number | -
2232
//! `filter_name` | The name of current filter | Text | -
2333
//!
34+
//! # Actions
35+
//!
2436
//! Action | Default button
2537
//! --------------|---------------
2638
//! `next_filter` | Right
@@ -44,6 +56,7 @@
4456
//! [[block.filters]]
4557
//! name = "some-project"
4658
//! filter = "project:some-project +PENDING"
59+
//! config_override = ["rc.context:none"]
4760
//! ```
4861
//!
4962
//! # Icons Used
@@ -75,6 +88,7 @@ impl Default for Config {
7588
filters: vec![Filter {
7689
name: "pending".into(),
7790
filter: "-COMPLETED -DELETED".into(),
91+
config_override: Default::default(),
7892
}],
7993
format: default(),
8094
format_singular: default(),
@@ -109,7 +123,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
109123
.error("Failed to create event stream")?;
110124

111125
loop {
112-
let number_of_tasks = get_number_of_tasks(&filter.filter).await?;
126+
let number_of_tasks = get_number_of_tasks(filter).await?;
113127

114128
let mut widget = Widget::new();
115129

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

150-
async fn get_number_of_tasks(filter: &str) -> Result<u32> {
164+
async fn get_number_of_tasks(filter: &Filter) -> Result<u32> {
165+
let args_iter = filter.config_override.iter().map(String::as_str).chain([
166+
"rc.gc=off",
167+
&filter.filter,
168+
"count",
169+
]);
151170
let output = Command::new("task")
152-
.args(["rc.gc=off", filter, "count"])
171+
.args(args_iter)
153172
.output()
154173
.await
155174
.error("failed to run taskwarrior for getting the number of tasks")?
@@ -166,4 +185,6 @@ async fn get_number_of_tasks(filter: &str) -> Result<u32> {
166185
pub struct Filter {
167186
pub name: String,
168187
pub filter: String,
188+
#[serde(default)]
189+
pub config_override: Vec<String>,
169190
}

0 commit comments

Comments
 (0)