1- import 'dart:convert' ;
21import 'dart:io' as io;
32
43import 'package:file/file.dart' ;
@@ -146,38 +145,41 @@ class RunnableScript {
146145 }
147146 if (exitCode != 0 ) {
148147 final e = io.ProcessException (
149- cmd, args, 'Process exited with error code: $exitCode ' , exitCode);
148+ cmd,
149+ args,
150+ 'Process exited with error code: $exitCode ' ,
151+ exitCode,
152+ );
150153 throw e;
151154 }
152- } catch (e) {
153- rethrow ;
154155 } finally {
155156 await _fileSystem.file (scrPath).delete ();
156157 }
157158 }
158159
159- Future <int > _runShellScriptFile (ScriptRunnerConfig config, scrPath) async {
160+ Future <int > _runShellScriptFile (
161+ ScriptRunnerConfig config,
162+ String scrPath,
163+ ) async {
160164 final result = await io.Process .start (
161165 config.shell.shell,
162166 [config.shell.shellExecFlag, scrPath],
163167 environment: {...? config.env, ...? env},
164168 workingDirectory: workingDir ?? config.workingDir,
169+ mode: io.ProcessStartMode .inheritStdio,
170+ includeParentEnvironment: true ,
165171 );
166- result.stdout.listen ((event) {
167- io.stdout.write (Utf8Decoder ().convert (event));
168- });
169- result.stderr.listen ((event) {
170- io.stdout.write (Utf8Decoder ().convert (event));
171- });
172172 final exitCode = await result.exitCode;
173173 return exitCode;
174174 }
175175
176176 String _getScriptPath () => _fileSystem.path
177177 .join (_fileSystem.systemTempDirectory.path, 'script_runner_$name .sh' );
178178
179- String _getScriptContents (ScriptRunnerConfig config,
180- {List <String > extraArgs = const []}) {
179+ String _getScriptContents (
180+ ScriptRunnerConfig config, {
181+ List <String > extraArgs = const [],
182+ }) {
181183 final script = "$cmd ${(args + extraArgs ).map (_utils .wrap ).join (' ' )}" ;
182184 switch (config.shell.os) {
183185 case OS .windows:
@@ -189,9 +191,11 @@ class RunnableScript {
189191 case OS .linux:
190192 case OS .macos:
191193 return [
192- ...preloadScripts.map ((e) => "alias ${e .name }='scr ${e .name }'" ),
194+ ...preloadScripts.map ((e) =>
195+ "[[ ! \$ (which ${e .name }) ]] && alias ${e .name }='scr ${e .name }'" ),
193196 script
194197 ].join ('\n ' );
195198 }
196199 }
197200}
201+
0 commit comments