{"id":13582341,"url":"https://github.com/ericfreese/rat","last_synced_at":"2025-05-16T13:03:27.402Z","repository":{"id":46820293,"uuid":"81499930","full_name":"ericfreese/rat","owner":"ericfreese","description":"Compose shell commands to build interactive terminal applications","archived":false,"fork":false,"pushed_at":"2021-09-23T15:29:04.000Z","size":7841,"stargazers_count":1284,"open_issues_count":18,"forks_count":53,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-04-09T08:04:55.625Z","etag":null,"topics":["command-line","git","rat","shell","terminal"],"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/ericfreese.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":"2017-02-09T22:09:54.000Z","updated_at":"2025-03-28T21:35:36.000Z","dependencies_parsed_at":"2022-09-26T18:20:54.920Z","dependency_job_id":null,"html_url":"https://github.com/ericfreese/rat","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfreese%2Frat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfreese%2Frat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfreese%2Frat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericfreese%2Frat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericfreese","download_url":"https://codeload.github.com/ericfreese/rat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535826,"owners_count":22087398,"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":["command-line","git","rat","shell","terminal"],"created_at":"2024-08-01T15:02:36.986Z","updated_at":"2025-05-16T13:03:27.361Z","avatar_url":"https://github.com/ericfreese.png","language":"Go","readme":"# Rat\n\n_Compose shell commands to build terminal applications_\n\n[![Join the chat at https://gitter.im/rat-chat/Lobby](https://badges.gitter.im/rat-chat/Lobby.svg)](https://gitter.im/rat-chat/Lobby?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![GoDoc](https://godoc.org/github.com/ericfreese/rat?status.svg)](https://godoc.org/github.com/ericfreese/rat)\n[![Build Status](https://travis-ci.org/ericfreese/rat.svg?branch=master)](https://travis-ci.org/ericfreese/rat)\n\n![](demo.gif)\n\n## Overview\n\nRat was developed as part of an effort to build a [tig](https://github.com/jonas/tig)-like application with very little opinionated UI logic, delegating instead to the capabilities of shell commands like `git log` with its `--pretty` and `--graph` options.\n\nShell commands are executed and the output is captured and displayed in pagers. Configurable annotators parse through the output, adding annotations that can be acted upon to run other shell commands.\n\n## Getting Started\n\n**WARNING: THIS IS ALL SUPER EXPERIMENTAL AND IS PROBABLY GOING TO CHANGE A LOT**\n\n### Install\n\n```shell\n$ go get github.com/ericfreese/rat\n$ go build \u0026\u0026 go install\n```\n\n### Configure\n\nRat is configured through a file `ratrc` in your home config directory ([`$XDG_CONFIG_HOME/rat`](https://specifications.freedesktop.org/basedir-spec/latest), `~/.config/rat` by default).\n\nRat pagers can be opened in one or more \"modes\". A mode is a configuration of \"annotators\" and \"key bindings\":\n\n- Annotators will look through the content of the pager for special bits of text that actions can be taken on. These bits of text are called \"annotations\". Each annotation has a start, an end, a class, and a value.\n- Key bindings define actions that can be taken on annotations.\n\n#### Keybindings\n\nFirst you'll need to set up some keybindings. Add the following to your `ratrc` and modify as desired:\n\n```shell\nbindkey C-r reload\nbindkey j   cursor-down\nbindkey k   cursor-up\nbindkey C-e scroll-down\nbindkey C-y scroll-up\nbindkey C-d page-down\nbindkey C-u page-up\nbindkey g,g cursor-first-line\nbindkey S-g cursor-last-line\nbindkey S-j parent-cursor-down\nbindkey S-k parent-cursor-up\nbindkey q   pop-pager\nbindkey S-q quit\nbindkey M-1 show-one\nbindkey M-2 show-two\nbindkey M-3 show-three\n```\n\n\u003ckbd\u003ectrl\u003c/kbd\u003e+\u003ckbd\u003ec\u003c/kbd\u003e will always quit.\n\n#### Mode Definitions\n\nThe `mode` keyword starts a mode definition.\n\n```shell\nmode \u003cname\u003e\n  ...\nend\n```\n\n#### Annotator Definitions\n\nInside of a mode definition, the `annotate` keyword starts an annotation definition.\n\n```shell\nmode \u003cname\u003e\n  annotate \u003ctype\u003e \u003cclass\u003e -- \u003coptions\u003e\nend\n```\n\n- `type`: The annotator type. Can be \"match\", \"regex\", or \"external\".\n- `class`: The class to apply to any annotations that this annotator finds.\n- `options`:\n    - If `type` is \"match\", this should be a shell command that outputs newline-delimited strings that the annotator will search for.\n    - If `type` is \"regex\", this should define a regular expression to search for (Golang regular expressions are supported).\n    - If `type` is \"external\", this should be the name of an executable located in `~/.config/rat/annotators/` that will be executed and sent the content of the pager via STDIN. The executable should print annotations to STDOUT in a specific binary format:\n        - Start: Byte offset from the beginning of STDIN (64-bit little-endian unsigned integer)\n        - End: Byte offset from the beginning of STDIN (64-bit little-endian unsigned integer)\n        - Value length: Length of found value string in bytes (64-bit little-endian unsigned integer)\n        - Value string: String of above-specified length (UTF-8 encoded)\n\n#### Keybinding Definitions\n\nThe `bindkey` keyword starts a keybinding definition.\n\n```shell\nmode \u003cname\u003e\n  bindkey \u003ckey\u003e [\u003cannotation-classes\u003e] [\u003cnew-pager-mode\u003e] -- \u003caction\u003e\nend\n\nbindkey \u003ckey\u003e \u003caction\u003e\nbindkey \u003ckey\u003e \u003cnew-pager-mode\u003e -- \u003ccmd\u003e\n```\n\n- `key`: A key combination that will trigger this action when pressed. Modifiers are added with `C-` and `S-`. See `lib/key_event.go` for a list of supported named keys.\n- `action`: A named action to run when the key is pressed. See action.go for a list of available actions.\n- `annotation-classes`: This action will only be triggered if annotations of these classes are present on the current line. If omitted, keybinding will work anywhere in the pager. These should be comma-delimited.\n- `new-pager-mode`: If the action will create a new pager, this defines the mode(s) to use when creating that pager.\n- `cmd`: A shell command to run when the specified key combination is pressed. Annotation values will be exported to the command process as variables named for their annotation class. The default is to open a new pager showing the output of the shell command, but several special prefixes can be used to specify different actions to be taken:\n    - `!`: Do not open a new pager. Execute the command and reload the current pager.\n    - `?!`: Like `!`, but confirm with the user first (will have to press 'y' for yes or 'n' for no).\n    - `\u003e`: Like the default, open a new pager with the contents of the shell command, but also set up a parent-child relationship so that the parent cursor can be moved up and down from inside the child pager with the `ParentCursorUp` and `ParentCursorDown` commands.\n\nNote: Keybindings that are not inside of a mode definition will always be available and do not have the special prefix behavior described above.\n\n#### Source configurations from separate files\n\nThe `source` keyword imports configuration rules from another file.\n\n```shell\nsource \u003cfile\u003e\n```\n\n- `file`: The path (relative to the rat config directory) to a file that contains valid rat configuration instructions\n\n#### Example\n\nAdd the following to your `ratrc` to build a simple file viewer/manager:\n\n```shell\nmode files\n  # Find all files (not directories) in the current directory and\n  # annotate with the class \"file\".\n  annotate match file -- ls -a1p | grep -v /\n\n  # When the cursor is on a line with an annotation of class \"file\" and\n  # the `enter` key is pressed, run `cat` with the value of the\n  # annotation (the filename) and display the output in a new pager with\n  # mode \"preview\". \n  bindkey enter file preview -- \u003ecat $file\n\n  # When the cursor is on a line with an annotation of class \"file\" and\n  # the `e` key is pressed, open the selected file in vim.\n  bindkey e     file         -- !vim $file\n\n  # When the cursor is on a line with an annotation of class \"file\" and\n  # Shift + `x` is pressed, delete the file if the user confirms it.\n  bindkey S-x   file         -- ?!rm $file\nend\n```\n\nRun `rat --mode files --cmd 'ls -al'` to try it out. You should see the output of `ls -al`. Move your cursor to a line with a regular file on it and press \u003ckbd\u003eEnter\u003c/kbd\u003e to view its contents. Try out the other keybindings. Try tweaking some things.\n\nSee `examples/` directory for more configuration examples.\n\n## Usage\n\n### Run\n\n``` shell\nrat [--mode=\u003cmode\u003e] [--cmd=\u003ccommand\u003e]\n```\n\n`--mode` defaults to `default`.\n\nIf `--cmd` is not provided, rat will read from STDIN.\n\n## Development\n\n### Dependencies\n\nDependencies are managed using [`glide`](https://github.com/Masterminds/glide).\n\n## License\n\nThis project is licensed under [MIT license](http://opensource.org/licenses/MIT). For the full text of the license, see the [LICENSE](LICENSE) file.\n","funding_links":[],"categories":["Go","terminal"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericfreese%2Frat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericfreese%2Frat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericfreese%2Frat/lists"}