Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/config/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use serde::{Deserialize, Serialize};
use serde::{
Deserialize,
Serialize,
};

#[derive(Deserialize, Serialize)]
pub struct Config {
Expand Down
12 changes: 7 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{
env::{self, VarError},
error::Error,
fs,
use std::env::{
self,
VarError,
};
use std::error::Error;
use std::fs;

pub mod config;

Expand All @@ -11,7 +12,8 @@ pub fn config_dir() -> Result<String, VarError> {
let root = env::var("USERPROFILE")?;
Ok(format!("{}\\.ftch", root))
} else {
let root = env::var("XDG_CONFIG_HOME")?;
let root = env::var("XDG_CONFIG_HOME")
.or_else(|_| env::var("HOME").map(|h| format!("{}/.config", h)))?;
Ok(format!("{}/ftch", root))
}
}
Expand Down
39 changes: 37 additions & 2 deletions src/data/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,42 @@ fn windows() -> Option<String> {
}

fn mac() -> Option<String> {
let output = Command::new("sw_vers").arg("-productName").output().ok()?;
let output = Command::new("sw_vers")
.arg("-productVersion")
.output()
.ok()?;

Some(String::from_utf8_lossy(&output.stdout).trim().to_string())
let version = String::from_utf8_lossy(&output.stdout).trim().to_string();
let codename = version_to_codename(&version);

Some(format!("macOS {codename}"))
}

fn version_to_codename(version: &str) -> String {
let major = version
.split('.')
.next()
.and_then(|v| v.parse::<u32>().ok())
.unwrap_or(0);

match major {
26 | 25 => "Tahoe",
24 => "Sequoia",
23 => "Sonoma",
22 => "Ventura",
21 => "Monterey",
20 => "Big Sur",
19 => "Catalina",
18 => "Mojave",
17 => "High Sierra",
16 => "Sierra",
15 => "El Capitan",
14 => "Yosemite",
13 => "Mavericks",
12 => "Mountain Lion",
11 => "Lion",
10 => "Snow Leopard",
_ => return version.to_string(),
}
.to_string()
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::VecDeque, error::Error};
use std::collections::VecDeque;
use std::error::Error;

mod ascii;
mod config;
Expand Down