{"id":29057672,"url":"https://github.com/mcmah309/sheller","last_synced_at":"2025-06-27T06:06:39.909Z","repository":{"id":206870697,"uuid":"717878382","full_name":"mcmah309/sheller","owner":"mcmah309","description":"Sheller brings ergonomic scripting to Dart by providing utilities for interacting with shells and converting output to Dart types. Allowing users to replace most or all of their scripts (e.g. bash or python) with Dart.","archived":false,"fork":false,"pushed_at":"2024-09-16T13:47:46.000Z","size":101,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T08:03:07.717Z","etag":null,"topics":["dart","scripting","shell","shell-scripting"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcmah309.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-11-12T21:43:41.000Z","updated_at":"2025-01-05T21:53:46.000Z","dependencies_parsed_at":"2023-11-12T22:29:20.610Z","dependency_job_id":"3b828e73-658d-4bc8-a91d-c5816db26c4c","html_url":"https://github.com/mcmah309/sheller","commit_stats":null,"previous_names":["mcmah309/sheller"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/mcmah309/sheller","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmah309%2Fsheller","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmah309%2Fsheller/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmah309%2Fsheller/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmah309%2Fsheller/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcmah309","download_url":"https://codeload.github.com/mcmah309/sheller/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcmah309%2Fsheller/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262202515,"owners_count":23274383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","scripting","shell","shell-scripting"],"created_at":"2025-06-27T06:06:38.677Z","updated_at":"2025-06-27T06:06:39.903Z","avatar_url":"https://github.com/mcmah309.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sheller\n\n[![Pub Version](https://img.shields.io/pub/v/sheller.svg)](https://pub.dev/packages/sheller)\n[![Dart Package Docs](https://img.shields.io/badge/documentation-pub.dev-blue.svg)](https://pub.dev/documentation/sheller/latest/)\n[![License: MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/mcmah309/sheller/actions/workflows/dart.yml/badge.svg)](https://github.com/mcmah309/sheller/actions)\n\nSheller brings ergonomic scripting to Dart by providing utilities for interacting with shells and converting output to Dart types. Allowing users to replace most or all of their scripts (e.g. bash or python) with Dart. e.g.\n```dart\nList\u003cFile\u003e files = $(\"cd $dir \u0026\u0026 find . -maxdepth 1 -type f\").lines();\n```\n\n### Table of Contents\n1. [Example](#examples)\n2. [Valid Conversion Types](#valid-conversion-types)\n3. [Custom Conversion Types](#custom-conversion-types)\n4. [Real Use Case - Protobuf Package Generation Script](#real-use-case---protobuf-package-generation-script)\n\n### Example\nWith Sheller you can easily write sync or async Dart scripts that interact with the host platform on `Linux`, `MacOs`, or `Windows`.\n```dart\nimport 'sheller/sync.dart';\n// import 'sheller/async.dart'; // alternative\n\n// Linux\nvoid main() {\n  // run process and print stdout to terminal\n  print($(\"netstat\")());\n  // run process and convert to Dart type\n  int number = $(\"echo 1\")();\n  assert(number == 1);\n  // built in support for types like json\n  String data ='{\\\\\"id\\\\\":1, \\\\\"name\\\\\":\\\\\"lorem ipsum\\\\\", \\\\\"address\\\\\":\\\\\"dolor set amet\\\\\"}';\n  Map\u003cString, dynamic\u003e json = $('echo $data')();\n  assert(json.entries.length == 3);\n  // split by spaces then convert\n  List\u003cdouble\u003e doubleList = $('echo 1  2   3').spaces();\n  assert(doubleList.length == 3);\n  // The class\n  $ shellClassInstance = $(\"echo 1\");\n  int id = shellClassInstance.pid;\n  int exitCode = shellClassInstance.exitCode;\n  int convertedResult = shellClassInstance();\n  assert(convertedResult == 1);\n  // split by lines then convert\n  List\u003cFile\u003e files = $(\"find . -maxdepth 1 -type f\").lines();\n  // Writing to a file\n  $(\"echo 1\") \u003e File(\"./temp\");\n  // Appending to a file\n  $(\"echo 2\") \u003e\u003e File(\"./temp\");\n}\n```\n\n### Valid Conversion Types\nBuilt in conversions for `stdout` of successful shells to\n```dart\nint\ndouble\nnum\nBigInt\nString\nbool // empty is false, non-empty is true.\nMap\u003cString, dynamic\u003e\nObject\nFileSystemEntity\nDirectory\nFile\nLink\n```\n\n### Custom Conversion Types\nEasily add your own custom conversion types to convert the output of the shell to a dart type. e.g.\n```dart\nclass IntConverter extends Converter\u003cString, int\u003e {\n  const IntConverter();\n\n  @override\n  int convert(String input) {\n    int? result = int.tryParse(input);\n    if (result == null) {\n      throw ShellConversionException(int, input);\n    }\n    return 99999;\n  }\n}\n\nvoid main() {\n  ShellConfig.addConverter(const IntConverter());\n  int number = $(\"echo 1\")();\n  assert(number == 99999);\n}\n```\n\n### Real Use Case - Protobuf Package Generation Script\n```dart\nvoid main() async {\n  const protoFilesDir = \"../../proto\";\n  const outputDir = \"../generated\";\n  const outputSrcDir = \"../generated/lib/src\";\n  if(Directory(outputDir).existsSync()){\n    Directory(outputDir).deleteSync(recursive: true);\n  }\n  Directory(outputSrcDir).createSync(recursive: true);\n\n  final protoFiles = Directory(protoFilesDir)\n      .listSync()\n      .whereType\u003cFile\u003e()\n      .where((file) =\u003e file.path.endsWith(\".proto\"))\n      .map((file) =\u003e file.path)\n      .toList();\n\n  final generateDartProtoFilesCommand = \"protoc -I=$protoFilesDir --dart_out=grpc:$outputSrcDir ${protoFiles.join(' ')}\";\n  print($(generateDartProtoFilesCommand)());\n\n  // Contains desired pubspec.yaml\n  const toCopyOver = \"./to_copy_over\";\n  print($(\"cp -r $toCopyOver/* $outputDir\")());\n\n  final generateBarrelFileCommand = \"cd $outputDir \u0026\u0026 dart pub run index_generator\";\n  print($(generateBarrelFileCommand)());\n  print(\"Done.\");\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmah309%2Fsheller","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcmah309%2Fsheller","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcmah309%2Fsheller/lists"}