{"id":15032770,"url":"https://github.com/ruby/shell","last_synced_at":"2025-04-04T19:12:08.689Z","repository":{"id":33650118,"uuid":"138372523","full_name":"ruby/shell","owner":"ruby","description":"Shell implements an idiomatic Ruby interface for common UNIX shell commands","archived":false,"fork":false,"pushed_at":"2023-10-19T05:32:07.000Z","size":220,"stargazers_count":61,"open_issues_count":1,"forks_count":8,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-03-28T18:13:20.886Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-23T04:56:27.000Z","updated_at":"2025-01-24T03:11:02.000Z","dependencies_parsed_at":"2024-06-18T21:39:11.273Z","dependency_job_id":null,"html_url":"https://github.com/ruby/shell","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fshell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fshell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fshell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby%2Fshell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby","download_url":"https://codeload.github.com/ruby/shell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234923,"owners_count":20905854,"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":["ruby"],"created_at":"2024-09-24T20:19:24.892Z","updated_at":"2025-04-04T19:12:08.667Z","avatar_url":"https://github.com/ruby.png","language":"Ruby","readme":"# Shell\n\nShell implements an idiomatic Ruby interface for common UNIX shell commands.\n\nIt provides users the ability to execute commands with filters and pipes, like `sh`/`csh` by using native facilities of Ruby.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'shell'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install shell\n\n## Usage\n\n### Temp file creation\n\nIn this example we will create three `tmpFile`'s in three different folders under the `/tmp` directory.\n\n```ruby\nsh = Shell.cd(\"/tmp\") # Change to the /tmp directory\nsh.mkdir \"shell-test-1\" unless sh.exist?(\"shell-test-1\")\n# make the 'shell-test-1' directory if it doesn't already exist\nsh.cd(\"shell-test-1\") # Change to the /tmp/shell-test-1 directory\nfor dir in [\"dir1\", \"dir3\", \"dir5\"]\n  if !sh.exist?(dir)\n    sh.mkdir dir # make dir if it doesn't already exist\n    sh.cd(dir) do\n      # change to the `dir` directory\n      f = sh.open(\"tmpFile\", \"w\") # open a new file in write mode\n      f.print \"TEST\\n\"            # write to the file\n      f.close                     # close the file handler\n    end\n    print sh.pwd                  # output the process working directory\n  end\nend\n```\n\n### Temp file creation with self\n\nThis example is identical to the first, except we're using `CommandProcessor#transact`.\n\n`CommandProcessor#transact` executes the given block against self, in this case `sh`; our Shell object. Within the block we can substitute `sh.cd` to `cd`, because the scope within the block uses `sh` already.\n\n```ruby\nsh = Shell.cd(\"/tmp\")\nsh.transact do\n  mkdir \"shell-test-1\" unless exist?(\"shell-test-1\")\n  cd(\"shell-test-1\")\n  for dir in [\"dir1\", \"dir3\", \"dir5\"]\n    if !exist?(dir)\n      mkdir dir\n      cd(dir) do\n        f = open(\"tmpFile\", \"w\")\n        f.print \"TEST\\n\"\n        f.close\n      end\n      print pwd\n    end\n  end\nend\n```\n\n### Pipe /etc/printcap into a file\n\nIn this example we will read the operating system file `/etc/printcap`, generated by `cupsd`, and then output it to a new file relative to the `pwd` of `sh`.\n\n```ruby\nsh = Shell.new\nsh.cat(\"/etc/printcap\") | sh.tee(\"tee1\") \u003e \"tee2\"\n(sh.cat \u003c \"/etc/printcap\") | sh.tee(\"tee11\") \u003e \"tee12\"\nsh.cat(\"/etc/printcap\") | sh.tee(\"tee1\") \u003e\u003e \"tee2\"\n(sh.cat \u003c \"/etc/printcap\") | sh.tee(\"tee11\") \u003e\u003e \"tee12\"\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/ruby/shell.\n\n## License\n\nThe gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fshell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby%2Fshell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby%2Fshell/lists"}