Repository: casey/just
File: src/recipe.rs (Rust)

Code before:
    }

    let shebang_line = evaluated_lines.first().ok_or_else(|| Error::Internal {
      message: "evaluated_lines was empty".to_owned(),
    })?;

    let shebang = Shebang::new(shebang_line).ok_or_else(|| Error::Internal {
      message: format!("bad shebang line: {}", shebang_line),
    })?;

    let tmp = if let Some(temp_dir) = &context.settings.temp_dir {
      tempfile::Builder::new()
        .tempdir_in(temp_dir.raw)
        .map_err(|error| Error::TmpdirIo {
          recipe: self.name(),
          io_error: error,
        })?
    } else {
      tempfile::Builder::new()
        .prefix("just")
        .tempdir()
        .map_err(|error| Error::TmpdirIo {
          recipe: self.name(),
          io_error: error,
        })?
    };

    let mut path = tmp.path().to_path_buf();
    path.push(shebang.script_filename(self.name()));

    {
      let mut f = fs::File::create(&path).map_err(|error| Error::TmpdirIo {
        recipe: self.name(),
        io_error: error,
      })?;
      let mut text = String::new();

      if shebang.include_shebang_line() {
        text += &evaluated_lines[0];
      } else {
        text += "\n";
      }

      text += "\n";
      // add blank lines so that lines in the generated script have the same line
      // number as the corresponding lines in the justfile
      for _ in 1..(self.line_number() + 2) {
        text += "\n";
      }
      for line in &evaluated_lines[1..] {
        text += line;

Review comment (refactor):
Maybe something like this to deduplicate a little bit, and preserve the temporary directory prefix:

```suggestion
    let mut tempdir_builder = tempfile::Builder::new();
    
    tempdir_builder.prefix("just");

    let tempdir = match &context.settings.tempdir {
      Some(tempdir) => tempdir_builder.tempdir_in(tempdir),
      None => tempdir_builder.tempdir(),
    }.map_err(|error| Error::TmpdirIo {
      recipe: self.name(),
      io_error: error,
    })?;
```

Code after:

    if config.dry_run {
      return Ok(());
    }

    let shebang_line = evaluated_lines.first().ok_or_else(|| Error::Internal {
      message: "evaluated_lines was empty".to_owned(),
    })?;

    let shebang = Shebang::new(shebang_line).ok_or_else(|| Error::Internal {
      message: format!("bad shebang line: {}", shebang_line),
    })?;

    let mut tempdir_builder = tempfile::Builder::new();
    tempdir_builder.prefix("just");
    let tempdir = match &context.settings.tempdir {
      Some(tempdir) => tempdir_builder.tempdir_in(context.search.working_directory.join(tempdir)),
      None => tempdir_builder.tempdir(),
    }
    .map_err(|error| Error::TmpdirIo {
      recipe: self.name(),
      io_error: error,
    })?;
    let mut path = tempdir.path().to_path_buf();
    path.push(shebang.script_filename(self.name()));

    {
      let mut f = fs::File::create(&path).map_err(|error| Error::TmpdirIo {
        recipe: self.name(),
        io_error: error,
      })?;
      let mut text = String::new();

      if shebang.include_shebang_line() {
        text += &evaluated_lines[0];
      } else {
        text += "\n";
      }

      text += "\n";
      // add blank lines so that lines in the generated script have the same line
      // number as the corresponding lines in the justfile
      for _ in 1..(self.line_number() + 2) {
        text += "\n";
      }
      for line in &evaluated_lines[1..] {
        text += line;
        text += "\n";
      }

      if config.verbosity.grandiloquent() {