{"id":13998388,"url":"https://github.com/linkdd/tshellout","last_synced_at":"2025-04-04T18:31:23.745Z","repository":{"id":182375125,"uuid":"668409177","full_name":"linkdd/tshellout","owner":"linkdd","description":"Typescript Shell Out library, to simplify writing and composing shell commands for NodeJS","archived":false,"fork":false,"pushed_at":"2023-08-18T16:45:03.000Z","size":69,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-20T17:05:32.186Z","etag":null,"topics":["nodejs","shell","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/linkdd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-07-19T18:30:07.000Z","updated_at":"2024-02-11T13:08:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"e927f1d7-44e8-4357-8934-7655532b392d","html_url":"https://github.com/linkdd/tshellout","commit_stats":null,"previous_names":["linkdd/tshellout"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Ftshellout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Ftshellout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Ftshellout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Ftshellout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdd","download_url":"https://codeload.github.com/linkdd/tshellout/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247229372,"owners_count":20905039,"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":["nodejs","shell","typescript"],"created_at":"2024-08-09T19:01:37.818Z","updated_at":"2025-04-04T18:31:23.372Z","avatar_url":"https://github.com/linkdd.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# TShellOut\n\nTypescript Shell Out library, to simplify writing and composing shell commands\nfor NodeJS.\n\n## :sparkles: Features\n\n - No dependencies\n - Composing commands with pipes (`|`), and sequential operators (`\u0026\u0026`, `||`)\n - Redirecting stdin, stdout and stderr\n - Writing Typescript strings to stdin\n\n## :memo: Usage\n\nInstall the package:\n\n```\n$ npm i tshellout\n```\n\nThen in a script:\n\n```typescript\nimport { command, script } from 'tshellout'\n\nconst cmd = command('echo', 'hello world')\nconst res = await cmd.run()\n\nconsole.log(res.exitCode)\nconsole.log(res.stdout.toString())\nconsole.log(res.stderr.toString())\n```\n\nMore examples:\n\n```typescript\n// echo \"hello world\" | tr -d \"\\r\" | tr -d \"\\n\" | wc -c\nconst cmd = command('echo', 'hello world')\n  .pipe(command('tr', '-d', '\"\\\\r\"'))\n  .pipe(command('tr', '-d', '\"\\\\n\"'))\n  .pipe(command('wc', '-c'))\nconst res = await cmd.run()\n```\n\n```typescript\n// myscript.sh || exit 1\nconst cmd = command('myscript.sh')\n  .or(command('exit', '1'))\nconst res = await cmd.run()\n```\n\n```typescript\n// script-1.sh \u0026\u0026 script-2.sh\nconst cmd = command('script-1.sh')\n  .and(command('script-2.sh'))\nconst res = await cmd.run()\n```\n\n```typescript\n// (script-1.sh || script-2.sh) \u0026\u0026 script-3.sh\nconst cmd = command('script-1.sh')\n  .or(command('script-2.sh'))\n  .and(command('script-3.sh'))\nconst res = await cmd.run()\n```\n\n```typescript\n// echo \"hello world\" \u003e greet.txt\nconst cmd = command('echo', 'hello world')\n  .redirectStdout('greet.txt')\nconst res = await cmd.run()\n```\n\n```typescript\n// cat \u003c\u003c data.txt\nconst cmd = command('cat')\n  .redirectStdin('data.txt')\nconst res = await cmd.run()\n```\n\n```typescript\n// cat \u003c\u003cEOF\n// hello world\n// EOF\nconst cmd = command('cat')\n  .writeStdin(Buffer.from('hello world\\n'))\nconst res = await cmd.run()\n```\n\nWe can also execute scripts:\n\n```typescript\nconst cmd = script.posix`\n  set -x\n  echo hello\n  echo world\n`\n\n// equivalent to:\n\nconst cmd = command('true')\n  .and(command('echo hello'))\n  .and(command('echo world'))\n```\n\nWe can also avoid capturing the output, and raise on errors:\n\n```typescript\nawait command('echo', 'hello world').exec()\n```\n\nParameters of both `run()` and `exec()` methods can be overridden:\n\n```typescript\nclass CommandBuilder {\n  // ...\n  async run(options?: {\n    capture: { stdout: boolean, stderr: boolean },\n    raiseOnError: boolean,\n  }) { /* ... */ }\n\n  async exec(options?: {\n    capture: { stdout: boolean, stderr: boolean },\n    raiseOnError: boolean,\n  }) { /* ... */ }\n}\n```\n\nThe defaults are:\n\n  - `run()`: `{ capture: { stdout: true, stderr: true }, raiseOnError: false }`\n  - `exec()`: `{ capture: { stdout: false, stderr: false }, raiseOnError: true }`\n\n## :page_facing_up: License\n\nThis project is released under the terms of the [MIT License](./LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Ftshellout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdd%2Ftshellout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Ftshellout/lists"}