https://github.com/pvdb/git-repl
The `git` REPL you've been looking for!
https://github.com/pvdb/git-repl
cli git repl subcommand terminal
Last synced: 11 months ago
JSON representation
The `git` REPL you've been looking for!
- Host: GitHub
- URL: https://github.com/pvdb/git-repl
- Owner: pvdb
- License: mit
- Created: 2025-01-13T07:27:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-15T20:02:06.000Z (about 1 year ago)
- Last Synced: 2025-03-11T11:54:31.480Z (11 months ago)
- Topics: cli, git, repl, subcommand, terminal
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# git-repl
The [generic, command-agnostic `repl` utility][pvdb/repl] can be installed as a `git` external command, after which it can be used as a regular `git` subcommand:
```sh
$ git repl
"git %s" >> ls-files
...
"git %s" >> status --short
...
"git %s" >> diff
...
"git %s" >> add -p README.md
...
"git %s" >> commit -m 'fix typo in README'
...
"git %s" >> ^D
$ _
```
As illustrated above, it provides a generic REPL environment that can be used to interact with `git` in a more interactive way than the regular `git` command-line tool allows.
## installation
The `git-repl` command is just a symlink to the generic `repl` command-line tool and therefore requires that `repl` is installed on your system first.
### step #1/3 - install `repl`
Install the latest version of the [generic `repl` script][pvdb/repl] in a directory that is on your `PATH`; you can adjust `REPL_INSTALL_DIR` in the below instructions to match your shell environment, something like:
REPL_INSTALL_DIR=/usr/local/bin
It comes in two flavors: a Ruby version and a Go version, so you have the choice between the two, depending on which language runtime you prefer to have installed on your system; both versions are functionally equivalent.
#### step #1.a - install the Ruby version of the `repl` script
[`repl.rb`][repl.rb] is the Ruby version of the `repl` script, which requires Ruby to be installed on your system, but has no other external dependencies _(that is: it only uses classes and modules from [Ruby's standard library](https://docs.ruby-lang.org/en/master/standard_library_md.html))_.
curl -s -O https://raw.githubusercontent.com/pvdb/repl/main/repl.rb
mv ./repl.rb "${REPL_INSTALL_DIR}/repl"
#### step #1.b - install the Go version of the `repl` script
[`repl.go`][repl.go] is the Go version of the `repl` script, which requires Go to be installed on your system, but has no other external dependencies _(that is: it only uses packages from [Go's standard library](https://pkg.go.dev/std))_.
curl -s -O https://raw.githubusercontent.com/pvdb/repl/main/repl.go
go build -o "${REPL_INSTALL_DIR}/repl" repl.go
rm repl.go
### step #2/3 - ensure and check that `repl` is executable
chmod 755 "${REPL_INSTALL_DIR}/repl"
repl --version
Depending on which version of the `repl` script you installed, the output of the `repl --version` command will be different:
* Ruby: `repl 1.0.0 (rlwrap 0.46.1, ruby 3.3.6)`
* Go: `repl 1.0.0 (rlwrap 0.46.1, go 1.23.4)`
Note that it also shows the versions of `rlwrap` (if installed) and the version of the language runtime that `repl` is using.
### step #3/3 - create `git-repl` as a symlink to `repl`
In the same directory on your `PATH` where `repl` is installed, create a symlink named `git-repl` to the `repl` script:
ln -s "${REPL_INSTALL_DIR}/repl" "${REPL_INSTALL_DIR}/git-repl"
This way you can run `git repl` without any changes to your system's `$PATH`.
## usage
Once installed, a `git` REPL can be launched using `git repl` (or less commonly using `git-repl` instead).
Running `git repl ()` is equivalent to running `repl git ()`, which means that the `git` command is the default command that is used in the REPL environment.
It also means that is supports all the same command-line options as the `repl` command, which can be used to customize the REPL environment to your liking; see `git repl --help` or `git repl --man` for more information.
## (optional) `readline` support
The `repl` utility requires the [`rlwrap`][rlwrap] utility to be installed on your system, which is a GNU readline wrapper that provides a command history and line editing capabilities for any command-line tool that lacks these features.
## example
Coming soon
## generate a `git`-specific completion file for `repl`
```sh
git --list-cmds="main,alias,others" > ${HOME}/.repl/git
```
The default `repl` completion directory is `${HOME}/.repl/` but can be overridden by setting the `REPL_COMPLETION_DIR` environment variable _(in your shell environment or else in `$(HOME)/.replrc`)_.
[pvdb/repl]: https://github.com/pvdb/repl
[rlwrap]: https://github.com/hanslub42/rlwrap
[repl.rb]: https://raw.githubusercontent.com/pvdb/repl/refs/heads/main/repl.rb
[repl.go]: https://raw.githubusercontent.com/pvdb/repl/refs/heads/main/repl.go