Skip to content

Commit 03ba5c5

Browse files
committed
update xfetch add --gen-config flag
1 parent 41ad407 commit 03ba5c5

5 files changed

Lines changed: 92 additions & 8 deletions

File tree

ROADMAP.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@
9696
## Phase 9 · CI/CD & Distribution <!-- phase:phase-9:cicd -->
9797

9898
- [ ] Setup GitHub Actions for automated builds (#102)
99-
- [ ] Create binary releases for Linux x86_64 (#103)
99+
- [x] Create binary releases for Linux x86_64 (#103)
100100
- [ ] Create binary releases for macOS (Intel & ARM) (#104)
101101
- [ ] Create binary releases for Windows (#105)
102-
- [ ] Setup AUR package for Arch Linux (#106)
102+
- [x] Setup AUR package for Arch Linux (#106)
103103
- [ ] Setup Homebrew tap for macOS (#107)
104104
- [ ] Setup PyPI or cargo registry for distribution (#108)
105105
- [ ] Setup automated changelog generation (#109)

configs/layout_pacman_full.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"header_icons": ["", "", "", "", ""],
2222
"footer_text": "GAME OVER",
2323
"icons": {
24-
"os": "",
24+
"os": "x",
2525
"kernel": "",
2626
"uptime": "󰔛",
2727
"packages": "",
@@ -34,7 +34,7 @@
3434
"disk": "󰋊",
3535
"battery": "",
3636
"local_ip": "󰩟",
37-
"palette": "🎨"
37+
"palette": "P"
3838
},
3939
"colors": {
4040
"os": "Red",

packaging/xpkg/XBUILD

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "xfetch"
3+
version = "0.1.0"
4+
release = 1
5+
description = "Cross-platform system information fetch tool written in Rust"
6+
url = "https://github.com/xscriptordev/xfetch"
7+
license = ["MIT"]
8+
arch = ["x86_64"]
9+
10+
[dependencies]
11+
depends = ["glibc"]
12+
makedepends = ["cargo", "gcc", "rust"]
13+
14+
[source]
15+
urls = []
16+
17+
[build]
18+
prepare = """
19+
REPO_ROOT=\"$(cd \"$startdir/../..\" && pwd)\"
20+
rm -rf \"$SRCDIR/xfetch-src\"
21+
mkdir -p \"$SRCDIR/xfetch-src\"
22+
cp -a \"$REPO_ROOT/.\" \"$SRCDIR/xfetch-src/\"
23+
rm -rf \"$SRCDIR/xfetch-src/target\"
24+
"""
25+
26+
build = """
27+
cd \"$SRCDIR/xfetch-src\"
28+
cargo build --release --locked
29+
"""
30+
31+
package = """
32+
cd \"$SRCDIR/xfetch-src\"
33+
install -Dm755 \"target/release/xfetch\" \"$PKGDIR/usr/bin/xfetch\"
34+
install -Dm644 LICENSE \"$PKGDIR/usr/share/licenses/xfetch/LICENSE\"
35+
install -Dm644 README.md \"$PKGDIR/usr/share/doc/xfetch/README.md\"
36+
cp -a configs \"$PKGDIR/usr/share/xfetch/\"
37+
cp -a logos \"$PKGDIR/usr/share/xfetch/\"
38+
"""

src/config.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ pub fn load_config(path: Option<String>) -> Config {
8686
let config_path = if let Some(p) = path {
8787
PathBuf::from(p)
8888
} else {
89-
let config_dir = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
90-
config_dir.join("xfetch").join("config.jsonc")
89+
default_config_path()
9190
};
9291

9392
// println!("Debug: Config path is {:?}", config_path);
@@ -118,3 +117,26 @@ pub fn load_config(path: Option<String>) -> Config {
118117
}
119118
}
120119
}
120+
121+
pub fn default_config_path() -> PathBuf {
122+
let config_dir = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
123+
config_dir.join("xfetch").join("config.jsonc")
124+
}
125+
126+
pub fn generate_config(path: Option<String>) -> std::io::Result<PathBuf> {
127+
let config_path = if let Some(p) = path {
128+
PathBuf::from(p)
129+
} else {
130+
default_config_path()
131+
};
132+
133+
if let Some(parent) = config_path.parent() {
134+
fs::create_dir_all(parent)?;
135+
}
136+
137+
// Keep generated defaults aligned with the curated pacman preset in the repo.
138+
let template = include_str!("../configs/layout_pacman_full.jsonc");
139+
fs::write(&config_path, template)?;
140+
141+
Ok(config_path)
142+
}

src/main.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,45 @@ mod config;
22
mod info;
33
mod ui;
44

5-
use crate::config::load_config;
5+
use crate::config::{generate_config, load_config};
66
use crate::info::Info;
77
use crate::ui::draw;
88
use clap::Parser;
99

1010
#[derive(Parser, Debug)]
11-
#[command(author, version, about, long_about = None)]
11+
#[command(
12+
author,
13+
version,
14+
about,
15+
long_about = None,
16+
after_help = "Examples:\n xfetch\n xfetch --config ~/.config/xfetch/config.jsonc\n xfetch --gen-config"
17+
)]
1218
struct Args {
1319
/// Path to config file
1420
#[arg(short, long)]
1521
config: Option<String>,
22+
23+
/// Generate a default config.jsonc (pacman layout) and exit
24+
#[arg(long)]
25+
gen_config: bool,
1626
}
1727

1828
fn main() {
1929
let args = Args::parse();
30+
31+
if args.gen_config {
32+
match generate_config(args.config.clone()) {
33+
Ok(path) => {
34+
println!("Generated config: {}", path.display());
35+
println!("Run xfetch to see the new layout.");
36+
return;
37+
}
38+
Err(err) => {
39+
eprintln!("Failed to generate config: {}", err);
40+
std::process::exit(1);
41+
}
42+
}
43+
}
2044

2145
// Load config
2246
let config = load_config(args.config);

0 commit comments

Comments
 (0)