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 | diff --git a/Makefile b/Makefile
index 9bf3140..7230341 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,3 @@
-PREFIX ?= /usr
-
all: build
build:
@@ -8,22 +6,22 @@ build:
install: build
sudo install -m755 target/release/walrs /usr/bin/walrs
sudo install -m644 walrs.1 /usr/share/man/man1/
- mkdir -p ~/.cache/walrs/templates/ ~/.cache/walrs/scripts/ ~/.cache/walrs/colorschemes/
- cp -r templates/* ~/.cache/walrs/templates/
- cp -r scripts/* ~/.cache/walrs/scripts/
- cp -r colorschemes/* ~/.cache/walrs/colorschemes/
+ sudo mkdir -p /usr/share/walrs/templates/ /usr/share/walrs/scripts/ /usr/share/walrs/colorschemes/
+ sudo cp -r templates/* /usr/share/walrs/templates/
+ sudo cp -r scripts/* /usr/share/walrs/scripts/
+ sudo cp -r colorschemes/* /usr/share/walrs/colorschemes/
bash ./autocomplete.sh
uninstall:
- sudo rm -rf /usr/bin/walrs ~/.cache/walrs ~/.config/walrs/ /usr/share/man/man1/walrs.1
+ sudo rm -rf /usr/bin/walrs /usr/share/walrs ~/.config/walrs/ /usr/share/man/man1/walrs.1
nix:
nix build
- mkdir -p ~/.cache/walrs/templates/ ~/.cache/walrs/scripts/ ~/.cache/walrs/colorschemes/
- sudo cp ./result/bin/walrs ~/.local/bin/
- cp -r templates/* ~/.cache/walrs/templates/
- cp -r scripts/* ~/.cache/walrs/scripts/
- cp -r colorschemes/* ~/.cache/walrs/colorschemes/
+ sudo install -m755 result/bin/walrs /usr/bin/walrs
+ sudo mkdir -p /usr/share/walrs/templates/ /usr/share/walrs/scripts/ /usr/share/walrs/colorschemes/
+ sudo cp -r templates/* /usr/share/walrs/templates/
+ sudo cp -r scripts/* /usr/share/walrs/scripts/
+ sudo cp -r colorschemes/* /usr/share/walrs/colorschemes/
bash ./autocomplete.sh
clean:
cargo clean
diff --git a/src/create_templates.rs b/src/create_templates.rs
index a85af19..becf8a9 100644
--- a/src/create_templates.rs
+++ b/src/create_templates.rs
@@ -1,4 +1,4 @@
-use crate::utils::{get_cache, get_config, warning};
+use crate::utils::{get_cache, get_config, share_files, warning};
use std::{
fs::{self, create_dir_all, read_to_string, write},
process::exit,
@@ -31,11 +31,7 @@ fn fill_template(
wallpaper: &str,
send: bool,
) {
- let output_path = format!(
- "{}/wal/{}",
- get_cache(send).to_string_lossy(),
- template_name
- );
+ let output_path = get_cache(send).join("wal").join(template_name);
let alpha = colors.1;
let mut result = template
@@ -121,9 +117,9 @@ fn fill_template(
}
pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str, send: bool) {
- let system_template_path = get_cache(send).join("walrs").join("templates");
- let user_template_path = format!("{}/walrs/templates/", get_config(send).to_string_lossy());
- let cache_path = format!("{}/wal/", get_cache(send).to_string_lossy());
+ let system_template_path = share_files().join("templates");
+ let user_template_path = get_config(send).join("walrs").join("templates");
+ let cache_path = get_cache(send).join("wal");
create_dir_all(&cache_path).unwrap_or_else(|_| {
warning("Create", "can't create the cache folder", send);
exit(1)
@@ -164,7 +160,7 @@ pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str, send: b
};
// Copy template to user directory
- let user_file_path = format!("{user_template_path}{name}");
+ let user_file_path = format!("{}{name}", user_template_path.display());
let _ = write(&user_file_path, &content);
fill_template(&name, &content, &colors, wallpaper, send);
diff --git a/src/main.rs b/src/main.rs
index 87c6739..afa0e5e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -136,14 +136,14 @@ fn main() {
} else {
let colorschemes_dir = config.join("walrs").join("colorschemes");
create_dir_all(&colorschemes_dir).unwrap();
- let walrs_cache = get_cache(send);
+ let walrs_cache = share_files();
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(),
+ walrs_cache.join("colorschemes").display(),
colorschemes_dir.display()
));
set_theme(v, send);
diff --git a/src/reload.rs b/src/reload.rs
index 823e175..ce29afe 100644
--- a/src/reload.rs
+++ b/src/reload.rs
@@ -1,4 +1,4 @@
-use crate::utils::{get_cache, get_config, info, run, warning};
+use crate::utils::{get_cache, get_config, info, run, share_files, warning};
use crate::wallpaper::change_wallpaper;
use std::fs::{create_dir_all, OpenOptions};
use std::fs::{read_dir, read_to_string};
@@ -57,7 +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 walrs_cache = share_files();
let file_path = cache.join("colors");
// read the colors file and load all the colors
diff --git a/src/theme.rs b/src/theme.rs
index 1b7ebcf..5d5aa55 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -1,7 +1,7 @@
use crate::{
create_templates::create_template,
reload::reload,
- utils::{get_cache, get_config, run, warning},
+ utils::{get_config, run, share_files, warning},
};
use std::fs::{create_dir_all, read_dir, read_to_string};
use std::path::Path;
@@ -64,7 +64,7 @@ pub fn set_theme(theme_name: String, send: bool) {
create_dir_all(&dis).unwrap();
run(&format!(
"cp -r {}/* {}",
- get_cache(send).join("walrs").join("colorschemes").display(),
+ share_files().join("colorschemes").display(),
base.join("walrs").join("colorschemes").display()
));
}
diff --git a/src/utils.rs b/src/utils.rs
index 8d61b1e..a48c45a 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -3,6 +3,10 @@ use std::path::{Path, PathBuf};
use std::process::{exit, Stdio};
use std::{fs, process::Command};
+pub fn share_files() -> PathBuf {
+ PathBuf::from("/usr").join("share").join("walrs")
+}
+
pub fn image_path(image: Option<String>, send: bool) -> String {
match image {
Some(ref v) if Path::new(v).exists() => match get_absolute_path(v) {
@@ -95,8 +99,10 @@ pub fn get_cache(send: bool) -> PathBuf {
}
pub fn get_absolute_path(path_str: &str) -> Option<String> {
- fs::canonicalize(Path::new(path_str))
- .ok()?
- .to_str()
- .map(|s| s.to_string())
+ let path = Path::new(path_str);
+ if !path.is_absolute() {
+ fs::canonicalize(path).ok()?.to_str().map(|s| s.to_string())
+ } else {
+ Some(path_str.to_string())
+ }
}
|