8 Commits

Author SHA1 Message Date
utox39
537a324275 build: bump version to 0.9.0 2025-08-06 00:03:00 +02:00
utox39
224a7d29d8 Merge pull request #11 from utox39/feat/parse-shell-version
Feat/parse shell version
2025-08-06 00:01:34 +02:00
utox39
eb477e5154 refactor(shell): remove the 'allocator' parameter 2025-08-05 23:13:42 +02:00
utox39
2d1c7506d8 feat(shell): parse bash shell version 2025-08-04 02:37:52 +02:00
utox39
428d882591 Merge pull request #10 from utox39/feat/handle-shell-env-var-not-found
Feat/handle shell env var not found
2025-08-04 00:40:29 +02:00
utox39
a1c62a56ae build: bump version to 0.8.1 2025-08-04 00:38:33 +02:00
utox39
5b423d1cef feat(shell): handle 'SHELL' env var not found 2025-08-04 00:35:09 +02:00
utox39
6574945e56 docs(README): update README 2025-08-02 00:25:25 +02:00
4 changed files with 42 additions and 4 deletions

View File

@@ -69,7 +69,7 @@ $ cp /path/to/zigfetch/config.json ~/.config/zigfetch/config.json
## Roadtrip ## Roadtrip
- [ ] Add ASCII art for each operating system and Linux distro - [ ] Add ASCII art for each operating system and Linux distro
- [ ] Add GPU info for Linux - [x] Add GPU info for Linux
- [ ] Add packages info for Linux - [ ] Add packages info for Linux
- [x] Add user customization - [x] Add user customization
- [ ] Add support for Windows - [ ] Add support for Windows

View File

@@ -10,7 +10,7 @@
// This is a [Semantic Version](https://semver.org/). // This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication. // In a future version of Zig it will be used for package deduplication.
.version = "0.8.0", .version = "0.9.0",
// Together with name, this represents a globally unique package // Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the // identifier. This field is generated by the Zig toolchain when the

View File

@@ -6,7 +6,9 @@ pub fn getUsername(allocator: std.mem.Allocator) ![]u8 {
} }
pub fn getShell(allocator: std.mem.Allocator) ![]u8 { pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
const shell = try std.process.getEnvVarOwned(allocator, "SHELL"); const shell = std.process.getEnvVarOwned(allocator, "SHELL") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown");
} else return err;
var child = std.process.Child.init(&[_][]const u8{ shell, "--version" }, allocator); var child = std.process.Child.init(&[_][]const u8{ shell, "--version" }, allocator);
defer allocator.free(shell); defer allocator.free(shell);
@@ -20,9 +22,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
_ = try child.wait(); _ = try child.wait();
if (std.mem.indexOf(u8, shell, "bash") != null) {
const bash_version = parseBashVersion(output);
defer allocator.free(output);
return try std.fmt.allocPrint(allocator, "{s} {s}", .{ "bash", bash_version.? });
}
return output; return output;
} }
fn parseBashVersion(shell_version_output: []u8) ?[]u8 {
const end_index = std.mem.indexOf(u8, shell_version_output, "(");
if (end_index == null) return null;
const version_keyword = "version ";
const version_keyword_index = std.mem.indexOf(u8, shell_version_output[0..end_index.?], version_keyword);
if (version_keyword_index == null) return null;
return shell_version_output[version_keyword_index.? + version_keyword.len .. end_index.?];
}
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 { pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) { const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown"); return allocator.dupe(u8, "Unknown");

View File

@@ -9,7 +9,9 @@ pub fn getUsername(allocator: std.mem.Allocator) ![]u8 {
} }
pub fn getShell(allocator: std.mem.Allocator) ![]u8 { pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
const shell = try std.process.getEnvVarOwned(allocator, "SHELL"); const shell = std.process.getEnvVarOwned(allocator, "SHELL") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown");
} else return err;
var child = std.process.Child.init(&[_][]const u8{ shell, "--version" }, allocator); var child = std.process.Child.init(&[_][]const u8{ shell, "--version" }, allocator);
defer allocator.free(shell); defer allocator.free(shell);
@@ -23,9 +25,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
_ = try child.wait(); _ = try child.wait();
if (std.mem.indexOf(u8, shell, "bash") != null) {
const bash_version = parseBashVersion(output);
defer allocator.free(output);
return try std.fmt.allocPrint(allocator, "{s} {s}", .{ "bash", bash_version.? });
}
return output; return output;
} }
fn parseBashVersion(shell_version_output: []u8) ?[]u8 {
const end_index = std.mem.indexOf(u8, shell_version_output, "(");
if (end_index == null) return null;
const version_keyword = "version ";
const version_keyword_index = std.mem.indexOf(u8, shell_version_output[0..end_index.?], version_keyword);
if (version_keyword_index == null) return null;
return shell_version_output[version_keyword_index.? + version_keyword.len .. end_index.?];
}
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 { pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) { const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
return allocator.dupe(u8, "Unknown"); return allocator.dupe(u8, "Unknown");