tempExecutableScriptFile function

File tempExecutableScriptFile(
  1. String content, {
  2. Directory? tempDir,
})

Writes content as executable *.sh file in a temp directory

The file name is the md5 hash of the content, therefore doesn't create a new file when called with the same content

Implementation

io.File tempExecutableScriptFile(String content, {Directory? tempDir}) {
  final io.Directory dir = tempDir ?? Directory.systemTemp.createTempSync();
  final script = dir.file('${content.md5}.sh')..createSync(recursive: true);
  script.writeAsStringSync(content);
  posix.chmod(script.path, permission: '755');
  return script;
}