mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-13 22:43: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,27 +1,24 @@
|
||||||
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))
|
||||||
|
&& d.path()
|
||||||
.extension()
|
.extension()
|
||||||
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
|
.map(|e| ["png", "jpg"].contains(&&*e.to_string_lossy()))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
|
|
Loading…
Reference in a new issue