{"id":18524388,"url":"https://github.com/binpash/libbash","last_synced_at":"2025-04-09T11:32:02.782Z","repository":{"id":206581504,"uuid":"706445922","full_name":"binpash/libbash","owner":"binpash","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-19T22:06:50.000Z","size":11343,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-20T21:56:23.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binpash.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-10-18T01:09:31.000Z","updated_at":"2024-04-15T03:39:16.359Z","dependencies_parsed_at":"2024-04-15T03:39:14.182Z","dependency_job_id":"ff9a66a0-6987-4f38-aac6-6b00cae5f3c9","html_url":"https://github.com/binpash/libbash","commit_stats":null,"previous_names":["sethsabar/libbash","binpash/libbash"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binpash%2Flibbash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binpash%2Flibbash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binpash%2Flibbash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binpash%2Flibbash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binpash","download_url":"https://codeload.github.com/binpash/libbash/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248031642,"owners_count":21036446,"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-11-06T17:41:14.581Z","updated_at":"2025-04-09T11:32:02.776Z","avatar_url":"https://github.com/binpash.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libbash\n\n**NOTE: This project is mostly functional, however there are a few minor bugs with the Bash source code causing issues with our API. Take a look at `test.py` to see which tests we are currently not testing because they will fail!**\n\n`libbash` can be installed via pip: https://pypi.org/project/libbash/\n\n## API\n\n*The `libbash` module contains the following functions.*\n\n`bash_to_ast` takes as input a file containing a bash script. It returns a `list` of `Command`s (see AST Classes below) representing the AST of the script. This function will throw an Exception if the script is invalid.\n\n`ast_to_json` takes as input a `list` of `Command`s and returns a list of json-style object's representing the `Command`s (we say that a json-style object is either a `map` from `str` to json-style object or a `str`, `int`, `null`, or `list` of json-style object).\n\n`ast_to_bash` takes as input a list of `Command`s and a filename and writes pretty-prints the script to the file. This function does not preserve line numbers, spacing, or other stylistic components.\n\n`==` the equality operator has been implemented in the `Command` class. This operator ignores stylistic fields stored in the AST, and considers two `Commands` to be equal if they are structurally equal. In most cases, a round-trip from `ast_to_bash` to `bash_to_ast` will result in the same script, but this is not guaranteed. In a few occasional cases, this round trip will wrap certain commands in a `Group` command, which doesn't change the functionality of the script but does change the AST.\n\n`run_tests` runs a testing suite on the above functions. If this fails, please consider creating a *New Issue* or making a *Pull Request* to fix the bug.\n\n## Command Objects\n\n*The `libbash.bash_command` module contains the classes which comprise our representation of a Bash command*\n\nThis library chooses to represent the AST of a bash script as a list of `Command` objects. To best understand what these objects look like, users are encouraged to understand the classes defined in [this directory](./libbash/bash_command). A great starting place to look at is the `Command` class in [command.py](./libbash/bash_command/command.py) class.\n\n## Limitations\n\nFor a Bash parser to be completely correct, it would actually need to execute the entire script! Consider the following script:\n\n```\ncurrent_hour=$(date +\"%H\")\n\nif [ \"$current_hour\" -lt 12 ]; then\n    alias while=random_string\nelse\n    echo \"It's after noon, no alias will be created.\"\nfi\n\ncounter=1\nwhile [ $counter -le 5 ]; do\n    echo \"Counter: $counter\"\n    ((counter++))\ndone\n```\n\nWhether `while` is aliased or not depends on the time of day that the script is run, and this affects the functionality of the `while` loop. This is because alias expansion is done\n*before* parsing in Bash. As this example shows, determining alias expansions is not possible without executing a Bash script. Therefore, one can not expect any uses of `alias` or\nother programs that change the script before parse-time to be reflected.\n\n## Additional Documents\n\n- [Difficulties Encountered During Development](https://docs.google.com/document/d/1Jn4z_QSTCoth_HvBtGE_DkAR0Z8O4B9eRKOKeV8njas/edit?usp=sharing) (just some notes I took)\n- [Bash Source Code Parsing Outline](https://docs.google.com/document/d/1qZ4OX3BBX7esKu_wB-GmGvgEL5VFEFFTtifKwQdwTDw/edit?usp=sharing) (a brief guide on how parsing works in the Bash source)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinpash%2Flibbash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinpash%2Flibbash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinpash%2Flibbash/lists"}