Commit 99a5dae6 authored by Nagy Tibor's avatar Nagy Tibor

screenfetch: Fix hostname, display the actual shell

It displayed empty hostname when the scheme of the current working directory was not the file:/ scheme.
Also the shell is not guaranteed to be Ion.
parent 8de89f84
...@@ -6,6 +6,7 @@ extern crate syscall; ...@@ -6,6 +6,7 @@ extern crate syscall;
use std::env; use std::env;
use std::fs::File; use std::fs::File;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::path::Path;
// std::fmt::Write conflicts with std::io::Write, hence the alias // std::fmt::Write conflicts with std::io::Write, hence the alias
use std::fmt::Write as FmtWrite; use std::fmt::Write as FmtWrite;
...@@ -17,7 +18,7 @@ const SECONDS_PER_DAY: i64 = 86400; ...@@ -17,7 +18,7 @@ const SECONDS_PER_DAY: i64 = 86400;
fn main() { fn main() {
let user = env::var("USER").unwrap_or(String::new()); let user = env::var("USER").unwrap_or(String::new());
let mut hostname = String::new(); let mut hostname = String::new();
if let Ok(mut file) = File::open("/etc/hostname") { if let Ok(mut file) = File::open("file:/etc/hostname") {
let _ = file.read_to_string(&mut hostname); let _ = file.read_to_string(&mut hostname);
} }
...@@ -51,6 +52,15 @@ fn main() { ...@@ -51,6 +52,15 @@ fn main() {
} }
} }
let mut shell = String::new();
{
if let Ok(shell_path) = env::var("SHELL") {
if let Some(file_name) = Path::new(&shell_path).file_name() {
shell = file_name.to_str().unwrap_or("").to_string();
}
}
}
let mut width = 0; let mut width = 0;
let mut height = 0; let mut height = 0;
if let Ok(display_name) = env::var("DISPLAY") { if let Ok(display_name) = env::var("DISPLAY") {
...@@ -117,7 +127,7 @@ fn main() { ...@@ -117,7 +127,7 @@ fn main() {
format!("\x1B[1;38;5;75mOS:\x1B[0m redox-os"), format!("\x1B[1;38;5;75mOS:\x1B[0m redox-os"),
format!("\x1B[1;38;5;75mKernel:\x1B[0m redox"), format!("\x1B[1;38;5;75mKernel:\x1B[0m redox"),
format!("\x1B[1;38;5;75mUptime:\x1B[0m {}", uptime_str), format!("\x1B[1;38;5;75mUptime:\x1B[0m {}", uptime_str),
format!("\x1B[1;38;5;75mShell:\x1B[0m ion"), format!("\x1B[1;38;5;75mShell:\x1B[0m {}", shell),
format!("\x1B[1;38;5;75mResolution:\x1B[0m {}x{}", width, height), format!("\x1B[1;38;5;75mResolution:\x1B[0m {}x{}", width, height),
format!("\x1B[1;38;5;75mDE:\x1B[0m orbital"), format!("\x1B[1;38;5;75mDE:\x1B[0m orbital"),
format!("\x1B[1;38;5;75mWM:\x1B[0m orbital"), format!("\x1B[1;38;5;75mWM:\x1B[0m orbital"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment