-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nils865/main
Improved Features
- Loading branch information
Showing
5 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use std::{env, path::Path}; | ||
|
||
pub fn cmd_cd(args: &Vec<String>) -> i8 { | ||
if args.len() == 0 { | ||
env::set_current_dir(Path::new(env::var("HOME").unwrap().as_str())).unwrap(); | ||
return 0; | ||
} | ||
|
||
match env::set_current_dir(Path::new(args[0].as_str())) { | ||
Ok(_) => return 0, | ||
Err(_) => { | ||
println!("cd: Directory \"{}\" not Found", args[0]); | ||
return 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use colored::Colorize; | ||
use std::{env, fs, path::Path}; | ||
|
||
pub fn cmd_ls(args: &Vec<String>) -> i8 { | ||
let dir: String; | ||
|
||
if args.len() == 0 { | ||
dir = env::current_dir().unwrap().display().to_string(); | ||
} else if args.len() == 1 { | ||
dir = args[0].clone(); | ||
} else { | ||
println!("ls: Too many Arguments Provided"); | ||
return 1; | ||
} | ||
|
||
let files = match fs::read_dir(Path::new(&dir)) { | ||
Ok(res) => res, | ||
Err(_) => { | ||
println!("ls: Directory \"{}\" not Found", dir); | ||
return 1; | ||
} | ||
}; | ||
|
||
for file in files { | ||
let path = file.unwrap().path(); | ||
|
||
let name = String::from( | ||
path.display() | ||
.to_string() | ||
.split("/") | ||
.last() | ||
.unwrap_or_default(), | ||
); | ||
|
||
if path.is_dir() { | ||
println!("{}", name.bright_cyan().bold()); | ||
} else { | ||
println!("{}", name); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
use colored::Colorize; | ||
use std::env; | ||
|
||
pub fn get_prompt(exit_code: i8) -> String { | ||
let mut prompt = String::new(); | ||
|
||
if exit_code == 0 { | ||
prompt.push_str(&"➜ ".green().to_string()); | ||
prompt.push_str(&"➜ ".green().to_string()); | ||
} else { | ||
prompt.push_str(&"➜ ".red().to_string()); | ||
prompt.push_str(&"➜ ".red().to_string()); | ||
} | ||
|
||
return prompt; | ||
let dir = env::current_dir().unwrap().display().to_string(); | ||
|
||
let mut display_dir = dir.split("/").last().unwrap(); | ||
|
||
if display_dir == "" { | ||
display_dir = "/"; | ||
} else if dir == env::var("HOME").unwrap() { | ||
display_dir = "~"; | ||
} | ||
|
||
prompt.push_str( | ||
&format!("{} ", display_dir) | ||
.bright_cyan() | ||
.to_string() | ||
.clone(), | ||
); | ||
|
||
return prompt.bold().to_string(); | ||
} |