Skip to content

Commit 0afe30d

Browse files
thewalkingforestTheWalkingForest
andauthored
Add xbps package manager to packages block (#2136)
* Add support for xbps package manager * Add `xbps` to cspell --------- Co-authored-by: TheWalkingForest <4783673-TheWalkingForest@users.noreply.gitlab.com>
1 parent 27bd364 commit 0afe30d

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

cspell.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ words:
183183
- wlsunset
184184
- wofi
185185
- wttr
186+
- xbps
186187
- xclip
187188
- xcolors
188189
- xesam

src/blocks/packages.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! - `pacman` for Arch based system
66
//! - `aur` for Arch based system
77
//! - `dnf` for Fedora based system
8+
//! - `xbps` for Void Linux
89
//!
910
//! # Configuration
1011
//!
@@ -28,6 +29,7 @@
2829
//! `pacman` | Number of updates available in Arch based system | Number | -
2930
//! `aur` | Number of updates available in Arch based system | Number | -
3031
//! `dnf` | Number of updates available in Fedora based system | Number | -
32+
//! `xbps` | Number of updates available in Void Linux | Number | -
3133
//! `total` | Number of updates available in all package manager listed | Number | -
3234
//!
3335
//! # Apt
@@ -146,16 +148,33 @@
146148
//! cmd = "dnf list -q --upgrades | tail -n +2 | rofi -dmenu"
147149
//! ```
148150
//!
151+
//!
152+
//! Xbps only config:
153+
//!
154+
//! ```toml
155+
//! [[block]]
156+
//! block = "packages"
157+
//! package_manager = ["xbps"]
158+
//! interval = 1800
159+
//! format = " $icon $xbps.eng(w:1) updates available "
160+
//! format_singular = " $icon One update available "
161+
//! format_up_to_date = " $icon system up to date "
162+
//! [[block.click]]
163+
//! # shows dmenu with available updates. Any dmenu alternative should also work.
164+
//! button = "left"
165+
//! cmd = "xbps-install -Mun | dmenu -l 10"
166+
//! ```
167+
//!
149168
//! Multiple package managers config:
150169
//!
151170
//! Update the list of pending updates every thirty minutes (1800 seconds):
152171
//!
153172
//! ```toml
154173
//! [[block]]
155174
//! block = "packages"
156-
//! package_manager = ["apt", "pacman", "aur","dnf"]
175+
//! package_manager = ["apt", "pacman", "aur", "dnf", "xbps"]
157176
//! interval = 1800
158-
//! format = " $icon $apt + $pacman + $aur + $dnf = $total updates available "
177+
//! format = " $icon $apt + $pacman + $aur + $dnf + $xbps = $total updates available "
159178
//! format_singular = " $icon One update available "
160179
//! format_up_to_date = " $icon system up to date "
161180
//! # If a linux update is available, but no ZFS package, it won't be possible to
@@ -179,6 +198,9 @@ use pacman::{Aur, Pacman};
179198
pub mod dnf;
180199
use dnf::Dnf;
181200

201+
pub mod xbps;
202+
use xbps::Xbps;
203+
182204
use regex::Regex;
183205

184206
use super::prelude::*;
@@ -206,6 +228,7 @@ pub enum PackageManager {
206228
Pacman,
207229
Aur,
208230
Dnf,
231+
Xbps,
209232
}
210233

211234
pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
@@ -232,6 +255,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
232255
let aur = any_format_contains!("aur");
233256
let pacman = any_format_contains!("pacman");
234257
let dnf = any_format_contains!("dnf");
258+
let xbps = any_format_contains!("xbps");
235259

236260
if !config.package_manager.contains(&PackageManager::Apt) && apt {
237261
config.package_manager.push(PackageManager::Apt);
@@ -245,6 +269,9 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
245269
if !config.package_manager.contains(&PackageManager::Dnf) && dnf {
246270
config.package_manager.push(PackageManager::Dnf);
247271
}
272+
if !config.package_manager.contains(&PackageManager::Xbps) && xbps {
273+
config.package_manager.push(PackageManager::Xbps);
274+
}
248275

249276
let warning_updates_regex = config
250277
.warning_updates_regex
@@ -275,6 +302,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
275302
config.aur_command.clone().error("aur_command is not set")?,
276303
)),
277304
PackageManager::Dnf => Box::new(Dnf::new()),
305+
PackageManager::Xbps => Box::new(Xbps::new()),
278306
});
279307
}
280308

src/blocks/packages/xbps.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use tokio::process::Command;
2+
3+
use super::*;
4+
5+
#[derive(Default)]
6+
pub struct Xbps;
7+
8+
impl Xbps {
9+
pub fn new() -> Self {
10+
Default::default()
11+
}
12+
}
13+
14+
#[async_trait]
15+
impl Backend for Xbps {
16+
fn name(&self) -> Cow<'static, str> {
17+
"xbps".into()
18+
}
19+
20+
async fn get_updates_list(&self) -> Result<Vec<String>> {
21+
let stdout = Command::new("xbps-install")
22+
.env("LC_LANG", "C")
23+
.args(["-M", "-u", "-n"])
24+
.output()
25+
.await
26+
.error("Problem running xbps-install command")?
27+
.stdout;
28+
29+
let updates = String::from_utf8(stdout).expect("xbps-install produced non-UTF8 output");
30+
let updates_list: Vec<String> = updates
31+
.lines()
32+
.filter(|line| line.len() > 1)
33+
.map(|line| line.to_string())
34+
.collect();
35+
36+
Ok(updates_list)
37+
}
38+
}

0 commit comments

Comments
 (0)