rgburke/grv

Add macros

sttts opened this issue · 3 comments

sttts commented

The killer feature of tig are macros. It would be awesome to get macro support for grv as well.

This is how they could look like:

:map <some-key> <some-view> !<some-other-external-command> $someGrvVariable ?"Some prompt for foo: "

The ? syntax means to ask the user for input. The $ syntax references variables like currently selected commit, current branch, current tag, view mode etc.

In other words: grv does not need many internal commands, it must be extensible.

This is a great suggestion and something that should definitely be added. I agree that grv should aim to be extensible as it will never be possible for it to support the full range of git commands and their flags. Ideally grv should support a limited set of common git operations by default (e.g. create branch, commit, etc...) and anything more advanced can be provided through user defined configuration.

I will start looking at adding this functionality to grv. Initially it will just be adding the ability to run an external command and view the output. Once that is done we can start considering which variables to expose and adding the user defined prompt. It will be useful to use tig as a reference throughout this process.

The latest code on master now supports macros. The set of available variables is described in the documentation here. Over time the number of variables supported will increase as more functionality is added.

A GRVVariableView has been added which displays the current values of all variables:
output
This view is not visible by default but can be added using one of the vsplit, addview, ... commands. e.g. :addview GRVVariableView.

These variables can be embedded in shell commands using the syntax ${variable}. For example, to cherry-pick the currently selected commit:

:!git cherry-pick ${commit}

As suggested keys can be mapped to commands. So this could be instead be specified with:

:map All gcp !git cherry-pick ${commit}

and run by entering the keys gcp.
To run commands in the background without displaying the output the @ prefix can be used instead of !:

:map All gcp @git cherry-pick ${commit}

Finally user input can also be prompted for using the syntax ?{promt text}. For example, to create a new branch from the currently selected commit:

:map All gb @git branch ?{New Branch Name: } ${commit}

Hopefully this implements all of the desired functionality. Please let me know if there are any suggestions or issues.

sttts commented

❤️