chore: refactor

This commit is contained in:
♥ Minnie ♥ 2025-06-10 12:51:06 +08:00
parent 84d84c151b
commit 2061bb4f74
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
2 changed files with 6 additions and 8 deletions

View file

@ -1,8 +1,8 @@
use std::env; // Provides Built-In Shell Functions.
pub fn cd(args: &[String]) { pub fn cd(args: &[String]) {
let path = args[0].to_string(); let path = args[0].to_string();
assert!(env::set_current_dir(&path).is_ok()); assert!(std::env::set_current_dir(&path).is_ok());
} }
pub fn help() { pub fn help() {

View file

@ -5,8 +5,6 @@ mod inbuilt;
use inbuilt::*; use inbuilt::*;
use mlua::prelude::*; use mlua::prelude::*;
use std::env;
use whoami::{username, devicename};
// Helper function for resolving aliases. // Helper function for resolving aliases.
fn resolve_alias(config: &mlua::Table, cmd: &str) -> Option<String> { fn resolve_alias(config: &mlua::Table, cmd: &str) -> Option<String> {
@ -31,8 +29,8 @@ fn resolve_prompt(config: &mlua::Table) -> String {
// Format current working directory. // Format current working directory.
fn fmt_cwd() -> String { fn fmt_cwd() -> String {
let home = env::var("HOME").unwrap_or_default(); let home = std::env::var("HOME").unwrap_or_default();
let cwd = env::current_dir() let cwd = std::env::current_dir()
.ok() .ok()
.and_then(|p| p.to_str().map(String::from)) .and_then(|p| p.to_str().map(String::from))
.unwrap_or_default(); .unwrap_or_default();
@ -48,8 +46,8 @@ fn fmt_cwd() -> String {
// Context for shell expansion. // Context for shell expansion.
fn context(s: &str) -> Option<String> { fn context(s: &str) -> Option<String> {
match s { match s {
"user" => Some(username()), "user" => Some(whoami::username()),
"host" => Some(devicename()), "host" => Some(whoami::devicename()),
"cwd" => Some(fmt_cwd()), "cwd" => Some(fmt_cwd()),
_ => None, _ => None,
} }