mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:15:53 +02:00
Bat
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
crate mod args;
|
||||
crate mod bat;
|
||||
crate mod cd;
|
||||
crate mod command;
|
||||
crate mod ls;
|
||||
|
32
src/commands/bat.rs
Normal file
32
src/commands/bat.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use crate::errors::ShellError;
|
||||
use crate::prelude::*;
|
||||
use derive_new::new;
|
||||
use prettyprint::PrettyPrinter;
|
||||
|
||||
#[derive(new)]
|
||||
pub struct Bat;
|
||||
|
||||
impl crate::Command for Bat {
|
||||
fn run(&self, args: CommandArgs<'caller>) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let target = match args.args.first() {
|
||||
// TODO: This needs better infra
|
||||
None => return Err(ShellError::string(format!("cat must take one arg"))),
|
||||
Some(v) => v.as_string()?.clone(),
|
||||
};
|
||||
|
||||
let cwd = args.env.cwd().to_path_buf();
|
||||
|
||||
let printer = PrettyPrinter::default()
|
||||
.line_numbers(false)
|
||||
.header(false)
|
||||
.grid(false)
|
||||
.build()
|
||||
.map_err(|e| ShellError::string(e))?;
|
||||
|
||||
let file = cwd.join(target);
|
||||
|
||||
let _ = printer.file(file.display().to_string());
|
||||
|
||||
Ok(VecDeque::new())
|
||||
}
|
||||
}
|
@ -68,6 +68,7 @@ fn main() -> Result<(), Box<Error>> {
|
||||
("ps", Box::new(ps::Ps)),
|
||||
("ls", Box::new(ls::Ls)),
|
||||
("cd", Box::new(cd::Cd)),
|
||||
("bat", Box::new(bat::Bat)),
|
||||
("skip", Box::new(skip::Skip)),
|
||||
("take", Box::new(take::Take)),
|
||||
("select", Box::new(select::Select)),
|
||||
|
Reference in New Issue
Block a user