Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
537a324275 | ||
|
|
224a7d29d8 | ||
|
|
eb477e5154 | ||
|
|
2d1c7506d8 | ||
|
|
428d882591 | ||
|
|
a1c62a56ae | ||
|
|
5b423d1cef | ||
|
|
6574945e56 |
@@ -69,7 +69,7 @@ $ cp /path/to/zigfetch/config.json ~/.config/zigfetch/config.json
|
||||
## Roadtrip
|
||||
|
||||
- [ ] 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
|
||||
- [x] Add user customization
|
||||
- [ ] Add support for Windows
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
// This is a [Semantic Version](https://semver.org/).
|
||||
// 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
|
||||
// identifier. This field is generated by the Zig toolchain when the
|
||||
|
||||
@@ -6,7 +6,9 @@ pub fn getUsername(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);
|
||||
defer allocator.free(shell);
|
||||
@@ -20,9 +22,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
||||
|
||||
_ = 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;
|
||||
}
|
||||
|
||||
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 {
|
||||
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||
return allocator.dupe(u8, "Unknown");
|
||||
|
||||
@@ -9,7 +9,9 @@ pub fn getUsername(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);
|
||||
defer allocator.free(shell);
|
||||
@@ -23,9 +25,26 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
||||
|
||||
_ = 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;
|
||||
}
|
||||
|
||||
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 {
|
||||
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||
return allocator.dupe(u8, "Unknown");
|
||||
|
||||
Reference in New Issue
Block a user