mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-13 20:12:59 +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 anyhow::Context;
|
||||||
|
use config::Config;
|
||||||
use rand::prelude::{IteratorRandom, SliceRandom};
|
use rand::prelude::{IteratorRandom, SliceRandom};
|
||||||
use std::{
|
use std::{path::Path, process::Command};
|
||||||
path::{Path, PathBuf},
|
|
||||||
process::Command,
|
|
||||||
};
|
|
||||||
use walkdir::{DirEntry, WalkDir};
|
use walkdir::{DirEntry, WalkDir};
|
||||||
use xinerama::head_count;
|
use xinerama::head_count;
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod xinerama;
|
mod xinerama;
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let paths = [
|
let config = Config::new()?;
|
||||||
PathBuf::from("/usr/share/backgrounds"),
|
|
||||||
Path::new(&std::env::var("HOME").context("couldn't get home directory")?)
|
|
||||||
.join(".local/share/backgrounds"),
|
|
||||||
];
|
|
||||||
|
|
||||||
let wallpapers = paths
|
let wallpapers = config
|
||||||
|
.paths
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(dir_iter)
|
.flat_map(dir_iter)
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter(|d| {
|
.filter(|d| {
|
||||||
d.path()
|
!config.exclude.iter().any(|e| d.path().starts_with(e))
|
||||||
.extension()
|
&& d.path()
|
||||||
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
|
.extension()
|
||||||
.unwrap_or(false)
|
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
|
||||||
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
.map(DirEntry::into_path);
|
.map(DirEntry::into_path);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue