Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ pub struct CliArgs {
#[arg(short = 'f', long, value_parser = clap::value_parser!(u8).range(4..=15))]
pub fps: Option<u8>,

/// Shell or program to launch. Defaults to $SHELL
#[arg()]
pub program: Option<String>,
/// Shell or program to launch with optional arguments. Defaults to $SHELL.
/// Use -- to separate t-rec options from shell arguments (e.g., t-rec -- /bin/bash -l)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
pub program: Vec<String>,

// --- Config-related args (not part of recording settings) ---
/// Use a named profile from the config file
Expand Down
22 changes: 13 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ fn main() -> Result<()> {

let settings = resolve_profiled_settings(&args)?;

let program: String = {
if let Some(prog) = &args.program {
prog.to_string()
} else {
let default = DEFAULT_SHELL.to_owned();
env::var("SHELL").unwrap_or(default)
}
};
let (program, program_args): (String, Vec<String>) = args
.program
.split_first()
.map(|(prog, rest)| (prog.clone(), rest.to_vec()))
.unwrap_or_else(|| {
(
env::var("SHELL").unwrap_or_else(|_| DEFAULT_SHELL.to_owned()),
vec![],
)
});
let (win_id, window_name) = current_win_id(&args)?;
let mut api = setup()?;
api.calibrate(win_id)?;
Expand Down Expand Up @@ -137,7 +139,9 @@ fn main() -> Result<()> {
};
thread::spawn(move || -> Result<()> { capture_thread(&rx, api, ctx) })
};
let interact = thread::spawn(move || -> Result<()> { sub_shell_thread(&program).map(|_| ()) });
let interact = thread::spawn(move || -> Result<()> {
sub_shell_thread(&program, &program_args).map(|_| ())
});

clear_screen();
io::stdout().flush().unwrap();
Expand Down
6 changes: 5 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ pub fn file_name_for(tc: &u128, ext: &str) -> String {

/// starts the main program and keeps interacting with the user
/// blocks until termination
pub fn sub_shell_thread<T: AsRef<OsStr> + Clone>(program: T) -> Result<ExitStatus> {
pub fn sub_shell_thread<T: AsRef<OsStr> + Clone, A: AsRef<OsStr>>(
program: T,
args: &[A],
) -> Result<ExitStatus> {
Command::new(program.clone())
.args(args)
.spawn()
.context(format!("failed to start {:?}", program.as_ref()))?
.wait()
Expand Down
Loading