shellIdentifier function

String shellIdentifier(
  1. String executableName
)

A name for executableName that is safe to use in shell identifiers: letters, digits and underscores only.

Implementation

String shellIdentifier(final String executableName) {
  final sanitized = executableName.replaceAll(RegExp(r'[^A-Za-z0-9_]'), '_');
  if (sanitized.isEmpty || RegExp(r'^[0-9]').hasMatch(sanitized)) {
    return '_$sanitized';
  }
  return sanitized;
}