From 6ed2643252c25be00d969edc95a29c75d49420b7 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Mon, 19 Jan 2026 22:11:45 -0800 Subject: [PATCH] ability to specify command when hitting enter (#1223) * ability to specify command when hitting enter * documentation * man page * generate man page and html * run default command through same logic as other commands impetuous: persist return val for display in promt if non-zero also future-proofs for other benefits / DRYness. no need for another eval invocation. * fix generated manpage --- Commands.md | 9 ++++++++- bin/git-repl | 9 ++++++++- man/git-repl.1 | 4 ++++ man/git-repl.html | 4 ++++ man/git-repl.md | 4 ++++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Commands.md b/Commands.md index 1b04250..9e70219 100644 --- a/Commands.md +++ b/Commands.md @@ -392,13 +392,20 @@ Type `exit`, `quit`, or `q` to end the repl session. Any arguments to git repl will be taken as the first command to execute in the repl. +You can specify a default command to run when hitting enter: + +```bash +git config --global git-extras.repl.on-enter-command "git status -sb" +``` + You can configure which character is used at the end of the prompt: (default `>`): ```bash git config --global git-extras.repl.prompt-character "±" ``` -You can specify the prefix for the prompt (default `git`): +You can specify the prefix for the prompt, or remove it (default `git`): + ```bash git config --global git-extras.repl.prefix "" ``` diff --git a/bin/git-repl b/bin/git-repl index b95d9d2..ef7181c 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -52,7 +52,14 @@ while true; do # Built-in commands case $cmd in ls) cmd=ls-files;; - "") continue;; + "") + on_enter_cmd=$(git config --get --default '' git-extras.repl.on-enter-command) + if test -n "$on_enter_cmd"; then + cmd="$on_enter_cmd" + else + continue + fi + ;; quit|exit|q) break;; esac diff --git a/man/git-repl.1 b/man/git-repl.1 index 162b0de..9816d4c 100644 --- a/man/git-repl.1 +++ b/man/git-repl.1 @@ -32,6 +32,10 @@ exit|quit|q .P Ends the repl session\. .SH "CONFIGURATION" +You can specify a default command to run when hitting enter: +.P +\fBgit config \-\-global git\-extras\.repl\.on\-enter\-command "git status \-sb"\fR +.P You can configure which character is used at the end of the prompt (default \fB>\fR): .P \fBgit config \-\-global git\-extras\.repl\.prompt\-character "±"\fR diff --git a/man/git-repl.html b/man/git-repl.html index d67ba2c..d3280ea 100644 --- a/man/git-repl.html +++ b/man/git-repl.html @@ -115,6 +115,10 @@

CONFIGURATION

+

You can specify a default command to run when hitting enter:

+ +

git config --global git-extras.repl.on-enter-command "git status -sb"

+

You can configure which character is used at the end of the prompt (default >):

diff --git a/man/git-repl.md b/man/git-repl.md index 4296909..0f8edc1 100644 --- a/man/git-repl.md +++ b/man/git-repl.md @@ -40,6 +40,10 @@ git-repl(1) -- git read-eval-print-loop ## CONFIGURATION + You can specify a default command to run when hitting enter: + + `git config --global git-extras.repl.on-enter-command "git status -sb"` + You can configure which character is used at the end of the prompt (default `>`):