bash_interop/scratch/
accounts.rs1use std::sync::Arc;
9
10use bash_strings::emit_array;
11
12use crate::rig::wire::Account;
13use crate::rig::{Micros, Shell, Stamp};
14
15pub fn account(pid: u32, zero: &str, flags: &str) -> Vec<String> {
18 let versinfo = emit_array(&["5", "3", "9", "1", "release", "x86_64-pc-linux-gnu"].map(String::from));
19 let command = if flags.contains('c') { "true" } else { "" };
20 let pid = pid.to_string();
21
22 [
23 "pid",
24 pid.as_str(),
25 "shlvl",
26 "5",
27 "subshell",
28 "0",
29 "versinfo",
30 versinfo.as_str(),
31 "bash",
32 "/usr/bin/bash",
33 "zero",
34 zero,
35 "flags",
36 flags,
37 "shellopts",
38 "braceexpand:hashall",
39 "bashopts",
40 "checkwinsize",
41 "command",
42 command,
43 "brought",
44 "()",
45 ]
46 .iter()
47 .map(ToString::to_string)
48 .collect()
49}
50
51pub fn shell(nth: usize, pid: u32, zero: &str, flags: &str) -> Arc<Shell> {
53 let stamp = Stamp {
54 sent_at: Micros(100),
55 heard_at: Micros(101),
56 };
57
58 Arc::new(
59 Shell::of(
60 nth,
61 Account {
62 stamp,
63 words: account(pid, zero, flags),
64 },
65 )
66 .expect("an account"),
67 )
68}
69
70pub fn reading(zero: &str) -> Arc<Shell> {
72 shell(0, 7, zero, "hB")
73}
74
75pub fn given(zero: &str) -> Arc<Shell> {
78 shell(0, 7, zero, "hBc")
79}