Repository: wezterm/wezterm (language: rust)

Issue:
Specify output file in `wezterm record`
**Is your feature request related to a problem? Please describe.**
When using `wezterm record`, there is no way to specify the output file.

**Describe the solution you'd like**
Add a new flag to the cli `-o` that accepts a path and write the asciicast to that file when that flag is present, otherwise, keep writing to a random filename in the temporary directory.

**Describe alternatives you've considered**
I can always look in the temp directory for the newest file that starts with the `wezterm-recording` prefix, but I think this is a better solution and easy to implement.

**Additional context**
If there are no issues with this feature, I'm willing to implement it myself, shouldn't be too hard.


Discussion / hints:

Fix patch:
diff --git a/docs/examples/cmd-synopsis-wezterm-record--help.txt b/docs/examples/cmd-synopsis-wezterm-record--help.txt
index 4787a467ebc..0ff345c4d38 100644
--- a/docs/examples/cmd-synopsis-wezterm-record--help.txt
+++ b/docs/examples/cmd-synopsis-wezterm-record--help.txt
@@ -9,4 +9,6 @@ Arguments:
 Options:
       --cwd <CWD>  Start in the specified directory, instead of the default_cwd
                    defined by your wezterm configuration
+  -o <OUTFILE>     Save asciicast to the specified file, instead of using a
+                   random file name in the temp directory
   -h, --help       Print help
diff --git a/wezterm/src/asciicast.rs b/wezterm/src/asciicast.rs
index 7cc05fcd96f..7636da68518 100644
--- a/wezterm/src/asciicast.rs
+++ b/wezterm/src/asciicast.rs
@@ -342,6 +342,11 @@ pub struct RecordCommand {
     #[arg(long)]
     cwd: Option<std::path::PathBuf>,
 
+    /// Save asciicast to the specified file, instead of
+    /// using a random file name in the temp directory
+    #[arg(short)]
+    outfile: Option<std::path::PathBuf>,
+
     /// Start prog instead of the default_prog defined by your
     /// wezterm configuration
     #[arg(value_parser)]
@@ -357,12 +362,24 @@ impl RecordCommand {
 
         let header = Header::new(&config, size, &prog);
 
-        let (cast_file, cast_file_name) = tempfile::Builder::new()
-            .prefix("wezterm-recording-")
-            // We use a .txt suffix for convenice when uploading to GH
-            .suffix(".cast.txt")
-            .tempfile()?
-            .keep()?;
+        let (cast_file, cast_file_name) = match self.outfile.as_ref() {
+            Some(outfile) => (
+                std::fs::File::options()
+                    .write(true)
+                    .truncate(true)
+                    .create(true)
+                    .open(outfile)?,
+                outfile.clone(),
+            ),
+            None => {
+                tempfile::Builder::new()
+                    .prefix("wezterm-recording-")
+                    // We use a .txt suffix for convenice when uploading to GH
+                    .suffix(".cast.txt")
+                    .tempfile()?
+                    .keep()?
+            }
+        };
         let mut cast_file = BufWriter::new(cast_file);
         writeln!(cast_file, "{}", serde_json::to_string(&header)?)?;
 


Test patch: