shellCommandExecutables function

List<String> shellCommandExecutables(
  1. String plan
)

External executables occupying command positions in plan.

Implementation

List<String> shellCommandExecutables(String plan) {
  final matches = RegExp(
    r'(?:^|&&|\|\||[;|\n]|[()])\s*'
    r'(?:[A-Za-z_][A-Za-z0-9_]*=[^\s;&|()]+\s+)*'
    r'([^\s;&|()]+)',
  ).allMatches(plan);
  final found = <String>{};
  for (final match in matches) {
    final executable = match.group(1)!;
    if (!_shellBuiltins.contains(executable)) found.add(executable);
  }
  return found.toList(growable: false);
}