Pi66

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

← back to log

remove built-in commands and turn them into scripts and fix some reload bloat

author: pixel2175
date: 2025-06-04 03:01
hash: 8c4acb2c08c30261b5bece221b07debd8a47c7dc

Diffstat:

M

Makefile
9 +-

A

scripts/NOTE/README
6 +

A

scripts/bspwm.sh
9 ++

A

scripts/i3.sh
10 ++

A

scripts/kitty.sh
10 ++

A

scripts/polybar.sh
10 ++

A

scripts/xrdb.sh
5 +

M

src/create_templates.rs
7 ++

M

src/reload.rs
121 +++++++++++-------------------

M

src/theme.rs
11 ++-

M

src/utils.rs
1

M

src/wallpaper.rs
7 +-
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
diff --git a/Makefile b/Makefile
index 72e7900..82d8ae9 100644
--- a/Makefile
+++ b/Makefile
@@ -5,11 +5,12 @@ build:

 install: build
    sudo install -m755 target/release/walrs /usr/bin/walrs
-   sudo install -d ./templates/ /etc/walrs/templates
-   sudo cp -r templates/ /etc/walrs/
-   bash ./autocomplete.sh
+   sudo mkdir -p /etc/walrs/templates/  /etc/walrs/scripts/ /etc/walrs/colorschemes/
+   sudo cp -r templates/* /etc/walrs/templates/
+   sudo cp -r scripts/* /etc/walrs/scripts/
+   sudo cp -r colorschemes/* /etc/walrs/colorschemes/
    sudo cp ./walrs.1 /usr/share/man/man1/
-   sudo cp -r colorschemes/ /etc/walrs/
+   bash ./autocomplete.sh

 uninstall:
    sudo rm -rf /usr/bin/walrs /etc/walrs/ ~/.config/walrs/ /usr/share/man/man1/walrs.1
diff --git a/scripts/NOTE/README b/scripts/NOTE/README
new file mode 100644
index 0000000..c3e167c
--- /dev/null
+++ b/scripts/NOTE/README
@@ -0,0 +1,6 @@
+walrs will read the directory and run all the scripts with bash
+so if you have any scripts want to run it after walrs done it job please but it here 
+if you want to run python scripts just make new shell script that runs python :)
+take it easy
+
+bash myscripts.sh
diff --git a/scripts/bspwm.sh b/scripts/bspwm.sh
new file mode 100755
index 0000000..cc3b9ba
--- /dev/null
+++ b/scripts/bspwm.sh
@@ -0,0 +1,9 @@
+#!/bin/env bash 
+
+bspwm() {
+    if pgrep -x bspwm >/dev/null; then
+        bspc wm -r
+        echo "Bspwm: bspwm colorscheme set"
+    fi
+}
+bspwm
diff --git a/scripts/i3.sh b/scripts/i3.sh
new file mode 100755
index 0000000..d069f0f
--- /dev/null
+++ b/scripts/i3.sh
@@ -0,0 +1,10 @@
+#!/bin/env bash 
+
+i3() {
+    if pgrep -x i3 >/dev/null; then
+        i3-msg reload
+        echo "i3: i3 colorscheme set"
+    fi
+}
+
+i3
diff --git a/scripts/kitty.sh b/scripts/kitty.sh
new file mode 100755
index 0000000..b338b7d
--- /dev/null
+++ b/scripts/kitty.sh
@@ -0,0 +1,10 @@
+#!/bin/env bash 
+
+kitty() {
+    if command -v kitty >/dev/null && pgrep kitty >/dev/null; then
+        kitty @ set-colors --all "$1/wal/colors-kitty.conf"
+        echo "Kitty: kitty colorscheme set"
+    fi
+}
+
+kitty "$HOME/.cache"
diff --git a/scripts/polybar.sh b/scripts/polybar.sh
new file mode 100755
index 0000000..322fe41
--- /dev/null
+++ b/scripts/polybar.sh
@@ -0,0 +1,10 @@
+#!/bin/env bash 
+
+polybar() {
+    if command -v polybar >/dev/null && pgrep polybar >/dev/null; then
+        pkill -USR1 polybar
+        echo "Polybar: polybar colorscheme set"
+    fi
+}
+
+polybar
diff --git a/scripts/xrdb.sh b/scripts/xrdb.sh
new file mode 100755
index 0000000..d9d768a
--- /dev/null
+++ b/scripts/xrdb.sh
@@ -0,0 +1,5 @@
+#!/bin/env bash 
+
+xrdb -merge -quiet "$HOME/.cache/wal/colors.Xresources"
+echo "Xrdb: xrdb colorscheme set"
+
diff --git a/src/create_templates.rs b/src/create_templates.rs
index 43d46a5..876bbd7 100644
--- a/src/create_templates.rs
+++ b/src/create_templates.rs
@@ -1,5 +1,8 @@
 use crate::utils::{get_cache, get_config, warning};
-use std::fs::{self, create_dir_all, read_to_string, write};
+use std::{
+    fs::{self, create_dir_all, read_to_string, write},
+    process::exit,
+};

 fn change(template: &str, colors: (u8, u8, u8), alpha: u8) -> String {
     let (r, g, b) = colors;
@@ -126,6 +129,7 @@ pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str, send: b
     let cache_path = format!("{}/wal/", get_cache(send).to_string_lossy().to_string());
     create_dir_all(&cache_path).unwrap_or_else(|_| {
         warning("Create", "can't create the cache folder", send);
+        exit(1)
     });

     // Check if user templates directory exists and has templates
@@ -149,6 +153,7 @@ pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str, send: b
     if !has_user_templates {
         create_dir_all(&user_template_path).unwrap_or_else(|_| {
             warning("Create", "can't create user template path", send);
+            exit(1)
         });

         if let Ok(entries) = fs::read_dir(system_template_path) {
diff --git a/src/reload.rs b/src/reload.rs
index f4d43b9..98130a2 100644
--- a/src/reload.rs
+++ b/src/reload.rs
@@ -1,77 +1,10 @@
-use std::fs::OpenOptions;
+use std::fs::{create_dir_all, OpenOptions};
 use std::fs::{read_dir, read_to_string};
 use std::io::Write;
-use std::process::{Command, Stdio};

+use crate::utils::{get_cache, get_home, info, run, warning};
 use crate::wallpaper;

-use crate::utils::{get_cache, info};
-
-fn run(command: &str) -> bool {
-    Command::new("sh")
-        .arg("-c")
-        .arg(command)
-        .stdout(Stdio::null())
-        .stderr(Stdio::null())
-        .status()
-        .map(|s| s.success())
-        .unwrap_or(false)
-}
-
-fn tty(cache: &str) {
-    let path = format!("{}/wal/colors-tty.sh", cache);
-    if Command::new("tty")
-        .arg("-s")
-        .status()
-        .map(|s| s.success())
-        .unwrap_or(false)
-    {
-        run(&format!("chmod +x {}", path));
-        run(&path);
-    }
-}
-
-fn xrdb(cache: &str, send: bool) {
-    if run("which xrdb") {
-        run(&format!(
-            "xrdb -merge -quiet {}/wal/colors.Xresources",
-            cache
-        ));
-        info("Xrdb", "xrdb colorscheme set", send);
-    }
-}
-
-fn i3(send: bool) {
-    if run("pgrep -x i3") {
-        run("i3-msg reload");
-        info("i3", "i3 colorscheme set", send);
-    }
-}
-
-fn bspwm(send: bool) {
-    if run("pgrep -x bspwm") {
-        run("bspc wm -r");
-        info("Bspwm", "bspwm colorscheme set", send);
-    }
-}
-
-fn kitty(cache: &str, send: bool) {
-    if run("which kitty") && run("pgrep kitty") {
-        run(&format!(
-            "kitty @ set-colors --all {}/wal/colors-kitty.conf",
-            cache
-        ));
-        info("Kitty", "kitty colorscheme set", send);
-    }
-}
-
-fn polybar(send: bool) {
-    if run("which polybar") && run("pgrep polybar") {
-        run("pkill -USR1 polybar");
-        info("Polybar", "polybar colorscheme set", send);
-    }
-}
-
 fn colors(colors: Vec<String>, send: bool) {
     for i in read_dir("/dev/pts/").expect("Can't load terminals") {
         let file = i.unwrap().file_name().into_string().unwrap();
@@ -113,9 +46,6 @@ pub fn reload(send: bool, set_wal: bool) {
         .map(|line| line.to_string())
         .collect();

-    // Spawn threads
-    let cache = get_cache(send).to_string_lossy().to_string();
-
     if set_wal {
         let wallpaper = read_to_string(format!("{}/wal/wal", cache))
             .expect("run 'cp /etc/walrs/templates/wal ~/.config/walrs/templates/' and restart app")
@@ -127,11 +57,46 @@ pub fn reload(send: bool, set_wal: bool) {
         wallpaper::change_wallpaper(wallpaper.as_str(), send);
     }
     colors(lines, send);
-    xrdb(&cache, send);
-    kitty(&cache, send);
-    i3(send);
-    bspwm(send);
-    polybar(send);
-    tty(&cache);
+
+    let scripts_dir = get_home(send).join(".config").join("walrs").join("scripts");
+
+    if !scripts_dir.exists() {
+        match create_dir_all(&scripts_dir) {
+            Ok(_) => {
+                run(&format!(
+                    "cp /etc/walrs/scripts/* {}",
+                    scripts_dir.to_string_lossy().to_string()
+                ));
+            }
+            Err(_) => return,
+        }
+    }
+
+    match read_dir(scripts_dir) {
+        Ok(v) => {
+            for scr in v {
+                let script = scr.unwrap().path();
+                if !script.is_file() {
+                    continue;
+                };
+                if !run(&format!(
+                    "bash {}",
+                    &script.canonicalize().unwrap().to_string_lossy()
+                )) {
+                    warning(
+                        "Script",
+                        &format!(
+                            "can't run {}",
+                            script.file_name().unwrap().to_string_lossy()
+                        ),
+                        send,
+                    );
+                }
+            }
+            info("Scripts", "scripts runs successfully", send);
+        }
+        _ => return,
+    }
+
     info("Colors", "colorscheme applied successfully", send);
 }
diff --git a/src/theme.rs b/src/theme.rs
index 38a9490..04d9664 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -4,6 +4,7 @@ use crate::{
     utils::{get_config, run, warning},
 };
 use std::fs::{create_dir_all, read_dir, read_to_string};
+use std::process::exit;

 pub fn collect_themes(subdir: &str, send: bool) -> Vec<String> {
     let base = get_config(send);
@@ -23,9 +24,12 @@ pub fn collect_themes(subdir: &str, send: bool) -> Vec<String> {
 }

 pub fn set_theme(theme_name: String, send: bool) {
-    let (dark, light) = (collect_themes("dark", send), collect_themes("light", send));
-    let mut theme: Vec<String> = dark.into_iter().chain(light).collect();
-    if theme.is_empty() {
+    let mut theme: Vec<String> = ["dark", "light"]
+        .iter()
+        .flat_map(|variant| collect_themes(variant, send))
+        .collect();
+
+    if !theme.is_empty() {
         let dis = get_config(send).join("wal").join("colorschemes");
         create_dir_all(&dis).unwrap();
         run(&format!(
@@ -64,5 +68,6 @@ pub fn set_theme(theme_name: String, send: bool) {
         reload(send, false);
     } else {
         warning("Theme", "Can't find theme", send);
+        exit(1)
     }
 }
diff --git a/src/utils.rs b/src/utils.rs
index 14d6ab9..1b6083e 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -31,7 +31,6 @@ pub fn print_colors(send: bool) {
 pub fn warning(title: &str, message: &str, send: bool) {
     if send {
         println!("[\x1b[33mW\x1b[0m] \x1b[31m{title}:\x1b[0m {message}.");
-        exit(1)
     }
 }

diff --git a/src/wallpaper.rs b/src/wallpaper.rs
index eecfb41..f0e81e2 100644
--- a/src/wallpaper.rs
+++ b/src/wallpaper.rs
@@ -2,7 +2,7 @@ use crate::utils::run;
 use crate::utils::{info, warning};
 use std::env;
 use std::path::Path;
-use std::process::{Command, Stdio};
+use std::process::{exit, Command, Stdio};

 fn run_with_output(command: &str) -> Option<String> {
     let output = Command::new("sh")
@@ -112,6 +112,7 @@ fn set_wm_wallpaper(img: &str, send: bool) {
         info("Wallpaper", "set solid background with xsetroot", send);
     } else {
         warning("Wallpaper", "can't find any app to set wallpaper", send);
+        exit(1)
     }
 }

@@ -202,6 +203,7 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
                 "no suitable wallpaper tool found for Sway",
                 send,
             );
+            exit(1)
         }
     } else if d.contains("awesome") {
         spawn(&format!(
@@ -255,6 +257,7 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
                 "no suitable Wayland wallpaper tool found",
                 send,
             );
+            exit(1);
         }
     } else if d.contains("wayfire") {
         // Wayfire compositor
@@ -310,7 +313,7 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
 pub fn change_wallpaper(img: &str, send: bool) {
     if !Path::new(img).is_file() {
         warning("Wallpaper", "invalid image path", send);
-        return;
+        exit(1)
     }

     match get_desktop_env() {