Skip to content

Commit

Permalink
fix(hok): Remove type.exe dep in hok cat
Browse files Browse the repository at this point in the history
address: #14

Signed-off-by: Chawye Hsu <[email protected]>
  • Loading branch information
chawyehsu committed Oct 8, 2024
1 parent 5c02321 commit 47a42c5
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions src/cmd/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,28 @@ pub fn cmd_cat(matches: &ArgMatches, session: &Session) -> Result<()> {
&result[num]
};

let cat = match is_program_available("bat.exe") {
true => "bat.exe",
false => "type",
};
let config = session.config();
let cat_args = match cat == "bat.exe" {
false => vec![],
let path = package.manifest().path();
println!("{}:", path.display().to_string().green());
match is_program_available("bat.exe") {
false => {
let content = std::fs::read_to_string(path)?;
println!("{}", content.trim());
}
true => {
let mut args = vec!["--no-paging"];
let config = session.config();
let mut cat_args = vec!["--no-paging"];
let cat_style = config.cat_style();
if !cat_style.is_empty() {
args.push("--style");
args.push(cat_style);
cat_args.push("--style");
cat_args.push(cat_style);
}
args.push("--language");
args.push("json");
args
}
};
cat_args.push("--language");
cat_args.push("json");

let path = package.manifest().path();
println!("{}:", path.display().to_string().green());

let mut child = Command::new("cmd")
.arg("/C")
.arg(cat)
.arg(path)
.args(cat_args)
.spawn()?;
child.wait()?;
let mut child = Command::new("bat.exe").arg(path).args(cat_args).spawn()?;
child.wait()?;
}
}
}
}
Ok(())
Expand Down

0 comments on commit 47a42c5

Please sign in to comment.