mirror of
https://github.com/sajenim/rush.git
synced 2025-06-28 01:44:21 +08:00
chore: refactor
This commit is contained in:
parent
84d84c151b
commit
2061bb4f74
2 changed files with 6 additions and 8 deletions
|
@ -1,8 +1,8 @@
|
|||
use std::env;
|
||||
// Provides Built-In Shell Functions.
|
||||
|
||||
pub fn cd(args: &[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() {
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -5,8 +5,6 @@ mod inbuilt;
|
|||
use inbuilt::*;
|
||||
|
||||
use mlua::prelude::*;
|
||||
use std::env;
|
||||
use whoami::{username, devicename};
|
||||
|
||||
// Helper function for resolving aliases.
|
||||
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.
|
||||
fn fmt_cwd() -> String {
|
||||
let home = env::var("HOME").unwrap_or_default();
|
||||
let cwd = env::current_dir()
|
||||
let home = std::env::var("HOME").unwrap_or_default();
|
||||
let cwd = std::env::current_dir()
|
||||
.ok()
|
||||
.and_then(|p| p.to_str().map(String::from))
|
||||
.unwrap_or_default();
|
||||
|
@ -48,8 +46,8 @@ fn fmt_cwd() -> String {
|
|||
// Context for shell expansion.
|
||||
fn context(s: &str) -> Option<String> {
|
||||
match s {
|
||||
"user" => Some(username()),
|
||||
"host" => Some(devicename()),
|
||||
"user" => Some(whoami::username()),
|
||||
"host" => Some(whoami::devicename()),
|
||||
"cwd" => Some(fmt_cwd()),
|
||||
_ => None,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue