mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-12 21:42:58 +01:00
add excludes to randomwallpaper
This commit is contained in:
parent
1ae7ea66ed
commit
a2dbcf89fa
2 changed files with 33 additions and 14 deletions
22
scripts/randomwallpaper/src/config.rs
Normal file
22
scripts/randomwallpaper/src/config.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use anyhow::Context;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct Config {
|
||||
pub paths: Vec<PathBuf>,
|
||||
pub exclude: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
paths: vec![
|
||||
PathBuf::from("/usr/share/backgrounds"),
|
||||
Path::new(&std::env::var("HOME").context("couldn't get home directory")?)
|
||||
.join(".local/share/backgrounds"),
|
||||
],
|
||||
|
||||
exclude: vec![PathBuf::from("/usr/share/backgrounds/xfce")],
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,30 +1,27 @@
|
|||
use anyhow::Context;
|
||||
use config::Config;
|
||||
use rand::prelude::{IteratorRandom, SliceRandom};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
use std::{path::Path, process::Command};
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
use xinerama::head_count;
|
||||
|
||||
mod config;
|
||||
mod xinerama;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let paths = [
|
||||
PathBuf::from("/usr/share/backgrounds"),
|
||||
Path::new(&std::env::var("HOME").context("couldn't get home directory")?)
|
||||
.join(".local/share/backgrounds"),
|
||||
];
|
||||
let config = Config::new()?;
|
||||
|
||||
let wallpapers = paths
|
||||
let wallpapers = config
|
||||
.paths
|
||||
.into_iter()
|
||||
.flat_map(dir_iter)
|
||||
.flatten()
|
||||
.filter(|d| {
|
||||
d.path()
|
||||
.extension()
|
||||
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
|
||||
.unwrap_or(false)
|
||||
!config.exclude.iter().any(|e| d.path().starts_with(e))
|
||||
&& d.path()
|
||||
.extension()
|
||||
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.map(DirEntry::into_path);
|
||||
|
||||
|
|
Loading…
Reference in a new issue