Skip to content

Commit 9d81b5a

Browse files
committed
Add: Init system support.
1 parent 2c57b40 commit 9d81b5a

4 files changed

Lines changed: 50 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ffetch"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
authors = ["0l3d <0l3dgit@gmail.com>"]
55
edition = "2021"
66
description = "Fast, minimal & Rust-powered system fetcher"

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ At its core, it works simply and the codebase is easy to understand. 💡
7575

7676
- `getLocale`
7777
Returns your system **locale** (e.g., `en_US`).
78+
79+
- `getTerm`
80+
Returns your **terminal emulator**.
81+
82+
- `getBackend`
83+
Returns your **windowing system**.
84+
85+
- `getInit`
86+
Returns your system **init** (e.g, `runit-init`).
87+
88+
- `getQT` or `getGTK`
89+
Returns your theme from environment variables.
7890

7991
# F-Fetch Style ANSI Color Codes Reference
8092

src/ffetch.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use display_info::DisplayInfo;
22
use lazy_static::lazy_static;
33
use regex::Regex;
4-
use std::{env, fs::read_to_string, process::Command};
4+
use std::{env, fs::{read_to_string, read_link, metadata}, process::Command};
55
use which::which;
66

77
lazy_static! {
@@ -46,6 +46,39 @@ pub fn get_kernel_version() -> String {
4646
kernel_result_full[2].to_string()
4747
}
4848

49+
/// Gets the system init system
50+
/// # Returns
51+
///
52+
/// Returns a `String` containing the init system name (e.g., "runit-init").
53+
///
54+
/// # Panics
55+
///
56+
/// A specific panic setting was not added, it could be because it cannot find file if it is panic.
57+
///
58+
/// # Examples
59+
///
60+
/// ```rust
61+
/// use ffetch::get_init_system();
62+
/// let init_system = get_init_system();
63+
/// println!("Init: {}", init_system);
64+
/// // Output: Init: runit-init
65+
/// ```
66+
pub fn get_init_system() -> String {
67+
let path = read_link("/sbin/init").unwrap();
68+
let init : &str = path.to_str().unwrap();
69+
70+
if metadata("/sbin/openrc").is_ok() {
71+
return "openrc".to_string();
72+
}
73+
74+
match init {
75+
"runit-init" => "runit".to_string(),
76+
"/lib/systemd/systemd" => "systemd".to_string(),
77+
_ => init.to_string(),
78+
}
79+
80+
}
81+
4982
/// Gets the system locale from environment variables.
5083
///
5184
/// Checks `LC_ALL` first, then `LANG`, and defaults to "C" if neither is set.

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ lazy_static! {
5151
static ref TERMINAL: String = ffetch::get_terminal();
5252
static ref KERNEL: String = ffetch::get_kernel_version();
5353
static ref CPU: String = ffetch::get_cpu_name();
54+
static ref INIT: String = ffetch::get_init_system();
5455
static ref MEMORY: String = ffetch::get_memory();
5556
static ref HOSTNAME: String = ffetch::get_hostname();
5657
static ref OSNAME: String = ffetch::get_os_name();
@@ -166,10 +167,11 @@ fn replace_syntax(conf: &str) -> String {
166167
.replace("getTerm", &TERMINAL)
167168
.replace("getGTK", &GTK)
168169
.replace("getQT", &QT)
170+
.replace("getInit", &INIT)
169171
.replace(&diskf, &ffetch::get_disks(&disk))
170172
.replace(&monitorf, &ffetch::get_monitor(index))
171173
// Fg Colors
172-
.replace("fg.black", "\x1b[30m")
174+
.replace("fg.black", "\x1b[30m")
173175
.replace("fg.red", "\x1b[31m")
174176
.replace("fg.green", "\x1b[32m")
175177
.replace("fg.yellow", "\x1b[33m")

0 commit comments

Comments
 (0)