Pi66

Home | Repos | About | Blog | Gaza

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

About | Files | Commits | Refs | License


change the configure dir and debloat in someplaces

Author: pixel2175
Date: 2025-06-06 05:11
commit: b043e29c

Stat

M src/main.rs 38 +19 -19
M src/reload.rs 7 +4 -3
M src/theme.rs 11 +6 -5
M src/utils.rs 21 +13 -8

Diff

diff --git a/src/main.rs b/src/main.rs
index e1ee390..ab409b8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,10 +12,10 @@ use create_templates::create_template;
 use get_colors::get_colors;
 use reload::reload;
 use std::fs::{copy, create_dir_all};
-use std::path::Path;
 use std::process::exit;
 use theme::{print_themes, set_theme, theme_exists};
 use utils::*;
+use wallpaper::change_wallpaper;

#[derive(FromArgs)] #[argh(description = "walrs - Generate colorscheme from image")] @@ -130,26 +130,25 @@ fn main() {

 // show or set theme from user
 if let Some(v) = arg.theme {
...
Show all
diff --git a/src/main.rs b/src/main.rs
index e1ee390..ab409b8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -12,10 +12,10 @@ use create_templates::create_template;
 use get_colors::get_colors;
 use reload::reload;
 use std::fs::{copy, create_dir_all};
-use std::path::Path;
 use std::process::exit;
 use theme::{print_themes, set_theme, theme_exists};
 use utils::*;
+use wallpaper::change_wallpaper;

#[derive(FromArgs)] #[argh(description = "walrs - Generate colorscheme from image")] @@ -130,26 +130,25 @@ fn main() {

 // show or set theme from user
 if let Some(v) = arg.theme {

+ let config = get_config(send); if v == "themes" { print_themes(send); + } else if theme_exists(&config) { + set_theme(v, send); } else { - let config = get_config(send); - if theme_exists(&config) { - set_theme(v, send); - } else { - let colorschemes_dir = get_config(send).join("walrs").join("colorschemes"); - create_dir_all(&colorschemes_dir).unwrap(); - let etc = Path::new("/etc/"); - if !theme_exists(etc) { - warning("theme", "Can't find configuration directory", send); - exit(1) - } - run(&format!( - "cp -r /etc/walrs/colorschemes/* {}", - colorschemes_dir.display() - )); - set_theme(v, send); - }; + let colorschemes_dir = config.join("walrs").join("colorschemes"); + create_dir_all(&colorschemes_dir).unwrap(); + let walrs_cache = get_cache(send); + if !theme_exists(&walrs_cache) { + warning("theme", "Can't find configuration directory", send); + exit(1) + } + run(&format!( + "cp -r {}/* {}", + walrs_cache.join("walrs").join("colorschemes").display(), + colorschemes_dir.display() + )); + set_theme(v, send); } exit(0); } @@ -176,7 +175,8 @@ fn main() { create_template(palette, &image_path, send); info("Template", "create templates", send);

- reload(send, true); + change_wallpaper(&image_path, send); + reload(send, false); print_colors(send); }; } diff --git a/src/reload.rs b/src/reload.rs index c45ae88..823e175 100644 --- a/src/reload.rs +++ b/src/reload.rs @@ -43,7 +43,6 @@ fn colors(colors: Vec<String>, send: bool) {

// read ~/.cache/wal/wal file and return the wallpaper path pub fn get_wallpaper(cache: &Path, send: bool) -> String { - read_to_string(cache.join("wal")) .unwrap_or_else(|_| { warning("Wallpaper", "Can't find the wallpaper", send); @@ -58,6 +57,7 @@ pub fn get_wallpaper(cache: &Path, send: bool) -> String {

pub fn reload(send: bool, set_wal: bool) { let cache = get_cache(send).join("wal"); + let walrs_cache = get_cache(send).join("walrs"); let file_path = cache.join("colors");

 // read the colors file and load all the colors

@@ -84,8 +84,9 @@ pub fn reload(send: bool, set_wal: bool) { match create_dir_all(&scripts_dir) { Ok(_) => { run(&format!( - "cp /etc/walrs/scripts/* {}", - scripts_dir.to_string_lossy() + "cp -r {}/* {}", + walrs_cache.join("scripts").display(), + scripts_dir.display() )); } Err(_) => return, diff --git a/src/theme.rs b/src/theme.rs index eac2838..1b7ebcf 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -1,14 +1,14 @@ use crate::{ create_templates::create_template, reload::reload, - utils::{get_config, run, warning}, + utils::{get_cache, get_config, run, warning}, }; use std::fs::{create_dir_all, read_dir, read_to_string}; use std::path::Path; use std::process::exit;

pub fn theme_exists(dir: &Path) -> bool { - dir.join("walrs").join("colorscheme").exists() || dir.join("wal").join("colorscheme").exists() + dir.join("walrs").join("colorschemes").exists() || dir.join("wal").join("colorschemes").exists() }

pub fn print_themes(send: bool) { @@ -60,11 +60,12 @@ pub fn set_theme(theme_name: String, send: bool) { .collect();

 if !theme.is&#95;empty() {

- let dis = get_config(send).join("wal").join("colorschemes"); + let dis = get_config(send).join("walrs").join("colorschemes"); create_dir_all(&dis).unwrap(); run(&format!( - "cp -r /etc/walrs/colorschemes/* {}/walrs/colorschemes", - base.display() + "cp -r {}/* {}", + get_cache(send).join("walrs").join("colorschemes").display(), + base.join("walrs").join("colorschemes").display() )); } theme.sort(); diff --git a/src/utils.rs b/src/utils.rs index 9aa7c0b..d86088c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -75,21 +75,26 @@ pub fn info(title: &str, message: &str, send: bool) { }

pub fn get_home(send: bool) -> PathBuf { - Path::new(&env::var("HOME").unwrap_or_else(|_| { + env::var("HOME").map(PathBuf::from).unwrap_or_else(|_| { warning("Home", "can't find the home dir", send); exit(1) - })) - .to_path_buf() + }) }

pub fn get_config(send: bool) -> PathBuf { - get_home(send).join(".config") + env::var_os("XDG_CONFIG_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| get_home(send).join(".config")) } pub fn get_cache(send: bool) -> PathBuf { - get_home(send).join(".cache") + env::var_os("XDG_CACHE_HOME") + .map(PathBuf::from) + .unwrap_or_else(|| get_home(send).join(".cache")) }

-pub fn get_absolute_path(path_str: &str) -> Option<String> { - let path = Path::new(path_str); - fs::canonicalize(path).ok()?.to_str().map(|s| s.to_string()) +fn get_absolute_path(path_str: &str) -> Option<String> { + fs::canonicalize(Path::new(path_str)) + .ok()? + .to_str() + .map(|s| s.to_string()) }

// Created by Pi66

// Copyright ©Pi66 2026