Opinionated Android 15+ Linux Terminal Setup
android
linux
command-line-tools
1use std::process::{self, Command};
2
3use anyhow::Error;
4use owo_colors::OwoColorize;
5
6pub fn run_command(cmd: &str, args: &[&str]) -> Result<(), Error> {
7 println!(
8 "{} {} {}",
9 "=>".green(),
10 cmd.green(),
11 args.join(" ").green()
12 );
13 let status = Command::new(cmd)
14 .args(args)
15 .env(
16 "PATH",
17 format!(
18 "{}:{}/.local/bin:{}",
19 "/nix/var/nix/profiles/default/bin",
20 std::env::var("HOME")?,
21 std::env::var("PATH")?
22 ),
23 )
24 .status()?;
25
26 if !status.success() {
27 println!("Command failed: {}", status);
28 process::exit(status.code().unwrap_or(1));
29 }
30
31 Ok(())
32}
33
34pub fn run_command_without_local_path(cmd: &str, args: &[&str]) -> Result<(), Error> {
35 println!(
36 "{} {} {}",
37 "=>".green(),
38 cmd.green(),
39 args.join(" ").green()
40 );
41 let status = Command::new(cmd).args(args).status()?;
42
43 if !status.success() {
44 println!("Command failed: {}", status);
45 process::exit(status.code().unwrap_or(1));
46 }
47
48 Ok(())
49}