{"id":16308980,"url":"https://github.com/bayashi/irir","last_synced_at":"2025-03-20T21:31:42.341Z","repository":{"id":167750100,"uuid":"643375519","full_name":"bayashi/irir","owner":"bayashi","description":"A filter to add colors for text lines generically from a YAML configuration file easily","archived":false,"fork":false,"pushed_at":"2024-06-10T05:54:00.000Z","size":112,"stargazers_count":9,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-11T21:19:19.110Z","etag":null,"topics":["cli","color","tool"],"latest_commit_sha":null,"homepage":"","language":"Go","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/bayashi.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,"publiccode":null,"codemeta":null}},"created_at":"2023-05-21T00:39:07.000Z","updated_at":"2024-09-11T09:05:52.000Z","dependencies_parsed_at":"2023-12-24T09:27:53.683Z","dependency_job_id":"096e600f-fd89-445b-b902-bba7931b0aa8","html_url":"https://github.com/bayashi/irir","commit_stats":null,"previous_names":["bayashi/irir"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayashi%2Firir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayashi%2Firir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayashi%2Firir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayashi%2Firir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bayashi","download_url":"https://codeload.github.com/bayashi/irir/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244084990,"owners_count":20395522,"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":["cli","color","tool"],"created_at":"2024-10-10T21:19:20.460Z","updated_at":"2025-03-20T21:31:42.011Z","avatar_url":"https://github.com/bayashi.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# irir\n\n\u003ca href=\"https://github.com/bayashi/irir/actions\" title=\"irir CI\"\u003e\u003cimg src=\"https://github.com/bayashi/irir/workflows/main/badge.svg\" alt=\"irir CI\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/bayashi/irir\" title=\"irir report card\" target=\"_blank\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/bayashi/irir\" alt=\"irir report card\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/bayashi/irir\" title=\"Go irir package reference\" target=\"_blank\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/bayashi/irir.svg\" alt=\"Go Reference: irir\"\u003e\u003c/a\u003e\n\n`irir` is a command line tool that provides a filter to add colors for text lines generically from a YAML configuration file easily.\n\n## Usage\n\nThis is a log file I want to add colors.\n\n```sh\n$ cat example.log\n2023/05/19 23:56:54 [info] GET /some/resource 200 0.001\n2023/05/19 23:56:55 [warn] GET /some/resource 200 0.001\n2023/05/19 23:56:56 [error] GET /some/resource 200 0.001\n2023/05/19 23:56:57 [info] GET /some/resource 200 0.001\n```\n\nthen, below is a coloring rule file for `log` in YAML.\n\n```sh\n$ cat ~/.config/irir/irir_rule.yaml\n---\nlog:\n- type: match\n  match: [info]\n  color: cyan\n  target: word\n- type: match\n  match: [warn]\n  color: yellow\n  target: word\n- type: match\n  match: [error]\n  color: bg_red\n  target: line\n```\n\nThen, you can filter the log file by `irir` with `log` rule.\n\n```sh\n$ cat example.log | irir log\n```\n\n![colored log file](https://user-images.githubusercontent.com/42190/239714614-fa153eec-a47d-49c8-a5c2-f70dfce97838.png)\n\nYas!\n\n## Rule YAML\n\n`irir` loads rules from YAML file. The rule file locates on your config directory of [XDG Base Directory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html). File name should be `irir_rule.yaml`.\n\nYou can start editing `irir_rule.yaml` by a command `irir --edit-config` except on Windows.\n\nYou can see the location of `irir_rule.yaml` by a command `irir --dump-config-path`.\n\nHere is the [JSON Schema file](https://raw.githubusercontent.com/bayashi/irir/main/.rule_schema.json) to support writing `irir_rule.yaml`.\n\n### irir_rule.yaml\n\nFirst key `log` is rule name that is specified in command line. You can name it as you like.\n\n```yaml\nlog:\n- type: match\n  match: [info]\n  color: cyan\n  target: word\n- type: match\n  match: [warn]\n  color: yellow\n  target: line\n- type: match\n  match: [error]\n  color: bg_red\n  target: line\n```\n\nAbove rules have 3 ways to color as list.\n\n### Each rule to color\n\n```\n- type: match\n  match: [info]\n  color: cyan\n  target: word\n```\n\n* `type`: This specifies how to match. It should be `match`, `prefix`, `suffix` or `regexp`. If `target` value is `word`, then you can use only `match` or `regexp`.\n* `match`: This is a string or a regexp string to match.\n* `color`: specific color name. See [the palette](https://github.com/bayashi/colorpalette/blob/main/colorpalette.go)\n* `target`: This specifies a scope of coloring. It should be `word` or `line`.\n\n### The case of regexp type\n\nIf `type` is `regexp`, then there are special way to set `regexp` for coloring words.\n\n#### Simple regexp case\n\nThe condition of regexp is `Ba.`. It will match 2 places with the line `Foo Bar Baz`.\n\n```sh\n$ cat example_file.txt\nFoo Bar Baz\n\n$ cat ~/.config/irir/irir_rule.yaml\nre:\n- type: regexp\n  match: Ba.\n  color: red\n  target: word\n```\n\nFilter above `example_file.txt` like below:\n\n```sh\n$ cat example_file.txt | irir re\n```\n\nOutput like this.\n\n![colored words by regexp](https://user-images.githubusercontent.com/42190/239843565-1945512c-9e03-49c6-8f4e-7b1b2aad90ba.png)\n\n#### Special chars in YAML for regexp\n\nAs for YAML spec, if you write backslash `\\` in string value, then you should enclose string value by single-quote like below:\n\n```yaml\n- type: regexp\n  match: '\\w+\\.go'\n```\n\nIf you enclose regexp with backslash by double-quote, then you should escape backslash by backslash:\n\n```yaml\n- type: regexp\n  match: \"\\\\w+\\\\.go\"\n```\n\nThis is bit confusing. Single-quoted regexp is easier.\n\n### Another example\n\nTo add colors for `go test` result by `gotest` rule.\n\n```yaml\ngotest:\n- type: prefix\n  match: \"--- PASS\"\n  color: green\n  target: line\n- type: prefix\n  match: \"ok\"\n  color: green\n  target: line\n- type: prefix\n  match: \"PASS\"\n  color: green\n  target: line\n- type: prefix\n  match: \"--- FAIL\"\n  color: red\n  target: line\n- type: prefix\n  match: \"FAIL\"\n  color: bg_red\n  target: line\n- type: prefix\n  match: \"--- SKIP\"\n  color: dark_yellow\n  target: line\n- type: match\n  match: \"=== RUN\"\n  color: gray\n  target: line\n- target: line\n  type: match\n  match: \"=== CONT\"\n  color: gray\n- type: match\n  match: \"=== PAUSE\"\n  color: gray\n  target: line\n- type: match\n  match: \"[no tests to run]\"\n  color: yellow\n  target: word\n- type: match\n  match: \"[no test files]\"\n  color: yellow\n  target: word\n- type: regexp\n  match: '[^\\/]+\\.go:\\d+'\n  color: cyan\n  target: word\n```\n\nThis is also helpful on wrapped `go test` through `make` in a project.\n\n```sh\n$ make test | irir gotest\n```\n\n![colored test result](https://user-images.githubusercontent.com/42190/239734820-f18006ce-6a9c-43b8-aaf0-c4f8ebd7a57b.png)\n\n## Default rule\n\nYou can specify default rule by ENV:`IRIR_DEFAULT_RULE`. Then you can omit rule argument in command line.\n\n```sh\nexport IRIR_DEFAULT_RULE=gotest\ngo test -v ./... | irir\n```\n\n## Full options\n\n`irir --help`\n\n```\nUsage: cat example.log | irir RULE_ID\nOptions:\n      --dump-colors        Dump color palette\n      --dump-config-path   Dump config file path\n      --dump-rule          Dump specified rule\n      --dump-rules         Show rules from config file\n      --dump-schema        Dump JSON Schema to validate the rule YAML config file\n      --edit-config        Invoke $EDITOR (or vi) to edit config YAML file\n  -h, --help               Show help (This message) and exit\n  -v, --version            Show version and build info and exit\n```\n\n## Wrap Command Feature (Experimental)\n\nNOTE: Don't execute a command from outside you don't handle. Just invoke only your own commands.\n\nBelow command line will color an output from `some-command` by `irir rule`.\n\n```sh\n$ iriri rule -- some-command\n```\n\nIt's as same as below.\n\n```sh\n$ some-command | irir rule\n```\n\nIf you often use `irir`, you can set alias with wrap command feature like below.\n\n```sh\n$ alias some-command=\"iriri rule -- some-command\"\n```\n\nThen you can avoid writing `| irir rule` on each time.\n\n## TIPS: Color for Github Actions\n\nGithub Actions doesn't have TTY. If you want to use `irir` in Github Actions, Then you should add `shell: 'script -q -e -c \"bash {0}\"'` line like below. This is an example how to color outputs of `go test` in Github Actions. \n\n```yaml\n- name: Install irir\n  run: |\n    go install github.com/bayashi/irir@latest\n    mkdir -p $HOME/.config/irir\n    curl -L https://raw.githubusercontent.com/bayashi/irir/main/configs/gotest.yaml \u003e $HOME/.config/irir/irir_rule.yaml\n\n- name: Run tests\n  shell: 'script -q -e -c \"bash {0}\"'\n  run: go test -v ./... | irir\n```\n\n## Installation\n\n### homebrew install\n\nIf you are using Mac:\n\n    brew tap bayashi/tap\n    brew install bayashi/tap/irir\n\n### binary install\n\nDownload binary from here: https://github.com/bayashi/irir/releases\n\n### go install\n\nIf you have golang environment:\n\n```cmd\ngo install github.com/bayashi/irir@latest\n```\n\n## License\n\nMIT License\n\n## Author\n\nDai Okabayashi: https://github.com/bayashi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayashi%2Firir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbayashi%2Firir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayashi%2Firir/lists"}