14
14
//! `format_up_to_date` | Same as `format`, but for when no updates are available. | `" $icon $count.eng(w:1) "`
15
15
//! `warning_updates_regex` | Display block as warning if updates matching regex are available. | `None`
16
16
//! `critical_updates_regex` | Display block as critical if updates matching regex are available. | `None`
17
+ //! `ignore_updates_regex` | Doesn't include updates matching regex in the count. | `None`
17
18
//! `ignore_phased_updates` | Doesn't include potentially held back phased updates in the count. | `false`
18
19
//!
19
20
//! Placeholder | Value | Type | Unit
@@ -67,6 +68,7 @@ pub struct Config {
67
68
pub format_up_to_date : FormatConfig ,
68
69
pub warning_updates_regex : Option < String > ,
69
70
pub critical_updates_regex : Option < String > ,
71
+ pub ignore_updates_regex : Option < String > ,
70
72
pub ignore_phased_updates : bool ,
71
73
}
72
74
@@ -91,6 +93,12 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
91
93
. map ( Regex :: new)
92
94
. transpose ( )
93
95
. error ( "invalid critical updates regex" ) ?;
96
+ let ignore_updates_regex = config
97
+ . ignore_updates_regex
98
+ . as_deref ( )
99
+ . map ( Regex :: new)
100
+ . transpose ( )
101
+ . error ( "invalid ignore updates regex" ) ?;
94
102
95
103
let mut cache_dir = env:: temp_dir ( ) ;
96
104
cache_dir. push ( "i3rs-apt" ) ;
@@ -124,7 +132,13 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
124
132
loop {
125
133
let mut widget = Widget :: new ( ) ;
126
134
let updates = get_updates_list ( config_file) . await ?;
127
- let count = get_update_count ( config_file, config. ignore_phased_updates , & updates) . await ?;
135
+ let count = get_update_count (
136
+ config_file,
137
+ config. ignore_phased_updates ,
138
+ ignore_updates_regex. as_ref ( ) ,
139
+ & updates,
140
+ )
141
+ . await ?;
128
142
129
143
widget. set_format ( match count {
130
144
0 => format_up_to_date. clone ( ) ,
@@ -189,11 +203,16 @@ async fn get_updates_list(config_path: &str) -> Result<String> {
189
203
async fn get_update_count (
190
204
config_path : & str ,
191
205
ignore_phased_updates : bool ,
206
+ ignore_updates_regex : Option < & Regex > ,
192
207
updates : & str ,
193
208
) -> Result < usize > {
194
209
let mut cnt = 0 ;
195
210
196
- for update_line in updates. lines ( ) . filter ( |line| line. contains ( "[upgradable" ) ) {
211
+ for update_line in updates
212
+ . lines ( )
213
+ . filter ( |line| line. contains ( "[upgradable" ) )
214
+ . filter ( |line| ignore_updates_regex. map_or ( true , |re| !re. is_match ( line) ) )
215
+ {
197
216
if !ignore_phased_updates || !is_phased_update ( config_path, update_line) . await ? {
198
217
cnt += 1 ;
199
218
}
0 commit comments