Skip to content

pvdb/git-repl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

git-repl

The generic, command-agnostic repl utility can be installed as a git external command, after which it can be used as a regular git subcommand:

$ 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 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 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).

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 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).

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 (<args>) is equivalent to running repl git (<args>), 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 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

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).

About

The `git` REPL you've been looking for!

Topics

Resources

License

Stars

Watchers

Forks