{"id":13623654,"url":"https://github.com/MrRio/shellwrap","last_synced_at":"2025-04-15T15:30:35.529Z","repository":{"id":5045051,"uuid":"6205572","full_name":"MrRio/shellwrap","owner":"MrRio","description":"Lovely PHP wrapper for using the command-line","archived":false,"fork":false,"pushed_at":"2022-11-04T22:32:47.000Z","size":45,"stargazers_count":742,"open_issues_count":9,"forks_count":55,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-04-07T16:12:29.894Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"facebook/mention-bot","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MrRio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-13T17:42:22.000Z","updated_at":"2025-02-11T21:31:34.000Z","dependencies_parsed_at":"2023-01-13T13:20:47.244Z","dependency_job_id":null,"html_url":"https://github.com/MrRio/shellwrap","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/MrRio%2Fshellwrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrRio%2Fshellwrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrRio%2Fshellwrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MrRio%2Fshellwrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MrRio","download_url":"https://codeload.github.com/MrRio/shellwrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961186,"owners_count":21189991,"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":[],"created_at":"2024-08-01T21:01:34.215Z","updated_at":"2025-04-15T15:30:35.508Z","avatar_url":"https://github.com/MrRio.png","language":"PHP","readme":"ShellWrap\n==================\n\nWhat is it?\n------------------\n\nIt's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together,\ncapture errors as PHP Exceptions and use a simple yet powerful syntax. Works with any command line tool automagically.\n\nFeatures \n------------------\n\n* Flexible and sexy syntax.\n* Exceptions are thrown if the executable returns an error.\n* Paths to binaries are automatically resolved.\n* All arguments are properly escaped.\n* Callback functions for streaming output.\n\n\nExamples\n------------------\n\n```php\n\u003c?php \nrequire_once 'vendor/autoload.php';\nuse MrRio\\ShellWrap as sh;\n\n// List all files in current dir\necho sh::ls();\n\n// Checkout a branch in git\nsh::git('checkout', 'master');\n\n// You can also pipe the output of one command, into another\n// This downloads example.com through cURL, follows location, then pipes through grep to \n// filter for 'html'\necho sh::grep('html', sh::curl('http://example.com', array(\n\t'location' =\u003e true\n)));\n\n// Touch a file to create it\nsh::touch('file.html');\n\n// Remove file\nsh::rm('file.html');\n\n// Remove file again (this fails, and throws an exception because the file doesn't exist)\n\ntry {\n\tsh::rm('file.html');\n} catch (ShellWrapException $e) {\n\techo 'Caught failing sh::rm() call';\n}\n\n\n// This throws an exception, as 'invalidoption' is not a valid argument\ntry {\n\techo sh::ls(array('invalidoption' =\u003e true));\n} catch (ShellWrapException $e) {\n\techo 'Caught failing sh::ls() call';\n}\n\n// Commands can be written multiple ways\nsh::git('reset', array('hard' =\u003e true), 'HEAD');\nsh::git('reset', '--hard', 'HEAD');\nsh::git(array('reset', '--hard', 'HEAD'));\n\n// Arguments passed in are automatically escaped, this expands to\n// date --date '2012-10-10 10:00:00'\necho sh::date(array(\n\t'date' =\u003e '2012-10-10 10:00:00'\n));\n\n// If arg keys are one letter, is assumes one dash prefixing it\n// date -d '2012-10-10 10:00:00'\necho sh::date(array(\n\t'd' =\u003e '2012-10-10 10:00:00'\n));\n\n\n?\u003e\n```\n\nExample: Tailing a file and adding timestamps to output\n-------------------------------------------------------\n\nYou can stream the output of a command into a callback function. For example:\n\n```php\nsh::tail('-f log', function($in) {\n\techo \"\\033[32m\" . date('Y-m-d H:i:s') . \"\\033[39m \" . $in;\n});\n```\n\nMake sure the file 'log' exists. This will output a timestamp, and the input. Try echoing into the log file.\n\nThe escape codes are to add a little colour to the terminal.\n\nInteractive Shell\n-----------------\n\nShellWrap also ships with an interactive shell mode. You can access this by typing:\n\n```\n./bin/shellwrap\n```\n\nWarning\n--------\n\nDon't use any user inputted data with these commands. Even with very paranoid filtering, you \ncan't know all the potential pitfalls of each command you're using. Use your noggin. \n\nAcknowledgements\n--------------------\n\nInspired by the Python project [sh by Andrew Moffat](http://pypi.python.org/pypi/sh)\n","funding_links":[],"categories":["命令行","Table of Contents","PHP","目录","Command Line","命令行( Command Line )","命令行 Command Line"],"sub_categories":["Command Line","命令行 Command Line"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMrRio%2Fshellwrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMrRio%2Fshellwrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMrRio%2Fshellwrap/lists"}