{"id":25175385,"url":"https://github.com/gbbirkisson/regop","last_synced_at":"2025-06-24T04:31:37.865Z","repository":{"id":276367566,"uuid":"929074071","full_name":"gbbirkisson/regop","owner":"gbbirkisson","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-05T07:42:28.000Z","size":111,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-05T08:41:47.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gbbirkisson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-07T18:58:43.000Z","updated_at":"2025-06-05T07:42:20.000Z","dependencies_parsed_at":"2025-02-07T20:27:13.023Z","dependency_job_id":"06b4db2d-7c74-408c-9d1b-3326a68185b2","html_url":"https://github.com/gbbirkisson/regop","commit_stats":null,"previous_names":["gbbirkisson/regop"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/gbbirkisson/regop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbbirkisson%2Fregop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbbirkisson%2Fregop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbbirkisson%2Fregop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbbirkisson%2Fregop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbbirkisson","download_url":"https://codeload.github.com/gbbirkisson/regop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbbirkisson%2Fregop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261604084,"owners_count":23183592,"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":"2025-02-09T12:31:21.111Z","updated_at":"2025-06-24T04:31:37.852Z","avatar_url":"https://github.com/gbbirkisson.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/gbbirkisson/regop\"\u003e\n      \u003cimg src=\"https://raw.githubusercontent.com/gbbirkisson/regop/main/logo.png\" alt=\"Logo\" height=\"128\"\u003e\n    \u003c/a\u003e\n    \u003cbr\u003eregop\n  \u003c/p\u003e\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  Easy file manipulation with \u003cb\u003ereg\u003c/b\u003eex and \u003cb\u003eop\u003c/b\u003eerators\n\u003c/p\u003e\n\n\u003c!-- vim-markdown-toc GFM --\u003e\n\n* [Usage 📖](#usage-)\n  * [TL;DR](#tldr)\n  * [Regex](#regex)\n  * [Operators](#operators)\n    * [Table](#table)\n* [Installation 💻](#installation-)\n  * [Using cargo](#using-cargo)\n  * [Using install script](#using-install-script)\n  * [Download pre-built binaries](#download-pre-built-binaries)\n* [Development 🚧](#development-)\n\n\u003c!-- vim-markdown-toc --\u003e\n\n## Usage 📖\n\n### TL;DR\n\nUse the `-r` to define regular expression capture groups and `-o` to define operators to\nmanipulate files:\n\n```bash\n# Increment edition in Cargo.toml by one\n$ regop \\\n    -r 'edition = \"(?\u003cedition\u003e[^\"]+)' \\\n    -o '\u003cedition\u003e:inc' \\\n    Cargo.toml\n\n┌───────────────────────────────────────────────────────────────────────────────\n│ Cargo.toml\n├───────────────────────────────────────────────────────────────────────────────\n│ 3   3    │ version = \"0.2.3\"\n│ 4        │-edition = \"2024\"\n│     4    │+edition = \"2025\"\n│ 5   5    │ repository = \"https://github.com/gbbirkisson/regop\"\n└───────────────────────────────────────────────────────────────────────────────\n```\n\n```bash\n# Swap anyhow major and patch version, increment minor by 3\n$ regop \\\n    -r 'anyhow = \"(?\u003cmajor\u003e\\d+)\\.(?\u003cminor\u003e\\d+)\\.(?\u003cpatch\u003e\\d+)\"' \\\n    -o '\u003cmajor\u003e:swap:\u003cpatch\u003e' \\\n    -o '\u003cminor\u003e:inc:3' \\\n    Cargo.toml\n┌───────────────────────────────────────────────────────────────────────────────\n│ Cargo.toml\n├───────────────────────────────────────────────────────────────────────────────\n│ 20  20   │ [dependencies]\n│ 21       │-anyhow = \"1.0.95\"\n│     21   │+anyhow = \"95.3.1\"\n│ 22  22   │ atty = \"0.2.14\"\n└───────────────────────────────────────────────────────────────────────────────\n```\n\n```bash\n# Multiply version numbers and convert package names to uppercase\n$ regop \\\n    -r '(?\u003cname\u003e\\w+) = \"(?\u003cversion\u003e\\d+)\"' \\\n    -o '\u003cname\u003e:upper' \\\n    -o '\u003cversion\u003e:mul:2' \\\n    dependencies.txt\n\n# Append suffix to filenames and prepend prefix\n$ regop \\\n    -r 'file: (?\u003cfilename\u003e\\w+)' \\\n    -o '\u003cfilename\u003e:prepend:backup_' \\\n    -o '\u003cfilename\u003e:append:.bak' \\\n    config.txt\n```\n\n```bash\n# Update all major versions in all toml files\n$ find -name '*.toml' | regop \\\n    -w \\\n    -r '\"(?\u003cmajor\u003e\\d+)\\.(?\u003cminor\u003e\\d+)\\.(?\u003cpatch\u003e\\d+)\"' \\\n    -o '\u003cmajor\u003e:inc'\n```\n\n```bash\n# Read from stdin and write to stdout\n$ cat Cargo.toml | regop -w \\\n    -r \"version = \\\"(?\u003cmajor\u003e\\d)\\.(?\u003cminor\u003e\\d)\" \\\n    -o \"\u003cmajor\u003e:rep:21\" \\\n    -\n```\n\n### Regex\n\nThe first piece of the puzzle is that you use regular expressions with named capture groups to\nextract some values in files. We use the rust\n[regex](https://docs.rs/regex/latest/regex/#example-named-capture-groups) crate, so you can use\nthat documentation for reference.\n\nAnother excellent resource is [regex101](https://regex101.com/). The site fully supports the\nrust [regex](https://docs.rs/regex/latest/regex/#example-named-capture-groups) crate and can\nhelp you make sense of complicated expressions:\n\nHere are some examples from [regex101](https://regex101.com/):\n- Extract `major`, `minor` and `patch` version from file: [link](https://regex101.com/r/wR5BJ5/1)\n- Extract `H2` subheadings from markdown: [link](https://regex101.com/r/ixUPEW/1)\n\n### Operators\n\nThe second piece is that you can manipulate your capture groups with operators. Operators\ntake the form of:\n\n```\n\u003ctarget\u003e:operation:parameter\n```\n\nWhere:\n\n- `\u003ctarget\u003e` is the name of your capture group (include the `\u003c` `\u003e` signs).\n- `operation` is the name of the desired operation (see [table](#table) below).\n- `parameter` is the parameter to the operation (see [table](#table) below). Note that\n`parameter` can reference another named capture.\n\n#### Table\n\n| Name      | Description           | Default | Valid parameters      | Examples                                        |\n| --------- | --------------------- | ------- | --------------------- | ----------------------------------------------- |\n| `inc`     | Increment number      | `1`     | `int`, `\u003ccapture\u003e`    | `\u003ca\u003e:inc`, `\u003ca\u003e:inc:5`, `\u003ca\u003e:inc:\u003cb\u003e`           |\n| `dec`     | Decrement number      | `1`     | `int`, `\u003ccapture\u003e`    | `\u003ca\u003e:dec`, `\u003ca\u003e:dec:5`, `\u003ca\u003e:dec:\u003cb\u003e`           |\n| `mul`     | Multiply number       | `None`  | `int`, `\u003ccapture\u003e`    | `\u003ca\u003e:mul:3`, `\u003ca\u003e:mul:\u003cb\u003e`                      |\n| `div`     | Divide number         | `None`  | `int`, `\u003ccapture\u003e`    | `\u003ca\u003e:div:2`, `\u003ca\u003e:div:\u003cb\u003e`                      |\n| `rep`     | Replace               | `None`  | `string`, `\u003ccapture\u003e` | `\u003ca\u003e:rep:mystring`, `\u003ca\u003e:rep:\u003cb\u003e`               |\n| `del`     | Delete                | `None`  | `None`                | `\u003ca\u003e:del`                                       |\n| `swap`    | Swap with another     | `None`  | `\u003ccapture\u003e`           | `\u003ca\u003e:swap:\u003cb\u003e`                                  |\n| `append`  | Append text           | `None`  | `string`, `int`       | `\u003ca\u003e:append:_suffix`, `\u003ca\u003e:append:123`          |\n| `prepend` | Prepend text          | `None`  | `string`, `int`       | `\u003ca\u003e:prepend:prefix_`, `\u003ca\u003e:prepend:v`          |\n| `upper`   | Convert to uppercase  | `None`  | `None`                | `\u003ca\u003e:upper`                                     |\n| `lower`   | Convert to lowercase  | `None`  | `None`                | `\u003ca\u003e:lower`                                     |\n\n## Installation 💻\n\n### Using cargo\n\n\u003c!--x-release-please-start-version--\u003e\n```bash\n$ cargo install --git https://github.com/gbbirkisson/regop.git --tag 0.5.0\n```\n\u003c!--x-release-please-end--\u003e\n\n### Using install script\n\n\u003c!--x-release-please-start-version--\u003e\n```bash\n$ curl --proto '=https' --tlsv1.2 -LsSf https://github.com/gbbirkisson/regop/releases/download/0.5.0/regop-installer.sh | sh\n```\n\u003c!--x-release-please-end--\u003e\n\n### Download pre-built binaries\n\nGo to the [latest release](https://github.com/gbbirkisson/regop/releases/latest) and download\nthe binary for your OS.\n\n## Development 🚧\n\nThis is a regular rust project, so `cargo` will we enough. But if you want you can use\n[just](https://github.com/casey/just):\n\n```bash\n$ just\nAvailable recipes:\n    build       # Build release\n    ci          # Run CI pipeline\n    default     # Show this help\n    dist        # Recreate release.yml workflow\n    install     # Install locally\n    lint-clippy # Run clippy linter\n    lint-fmt    # Run fmt linter\n    run         # Little test runs\n    test        # Run tests\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbbirkisson%2Fregop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbbirkisson%2Fregop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbbirkisson%2Fregop/lists"}