From b9bd309a87ddacbc4baef3954255f30d20420f80 Mon Sep 17 00:00:00 2001 From: John Bachir Date: Mon, 19 Jan 2026 16:15:42 -0800 Subject: [PATCH] Improve `git-repl` prompt (#1224) * repl config ideas * documentation * Update bin/git-repl Co-authored-by: Edwin Kofler * separator * man page and web docs * always use dir for project name --------- Co-authored-by: Edwin Kofler --- Commands.md | 17 +++++++++++++++++ bin/git-repl | 15 ++++++++++++++- man/git-repl.1 | 16 +++++++++++++--- man/git-repl.html | 22 +++++++++++++++++++--- man/git-repl.md | 15 +++++++++++++++ 5 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Commands.md b/Commands.md index fa59614..1b04250 100644 --- a/Commands.md +++ b/Commands.md @@ -392,6 +392,23 @@ 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 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`): +```bash +git config --global git-extras.repl.prefix "" +``` + +You can have the name of the current git repo shown in the prompt (default `false`): + +```bash +git config --global git-extras.repl.show-project-name "true" +``` + ```bash $ git repl git version 2.34.1 diff --git a/bin/git-repl b/bin/git-repl index a706de3..b95d9d2 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -19,7 +19,20 @@ while true; do else es_string="" fi - prompt="git$cur_string$es_string> " + prompt_character=$(git config --get --default '>' git-extras.repl.prompt-character) + + prefix=$(git config --get --default 'git' git-extras.repl.prefix) + + show_project_name=$(git config --get --default 'false' git-extras.repl.show-project-name) + if [[ "$show_project_name" == "true" ]]; then + project_name=" $(basename "$(git rev-parse --show-toplevel)" .git)" + else + project_name="" + fi + + prompt_base="$prefix$project_name$cur_string$es_string$prompt_character" + prompt_base_stripped=$(echo "$prompt_base" | awk '{$1=$1};1') + prompt="$prompt_base_stripped " # Use arguments as a command if any are provided. if [ $# -ne 0 ]; then diff --git a/man/git-repl.1 b/man/git-repl.1 index b3721f4..162b0de 100644 --- a/man/git-repl.1 +++ b/man/git-repl.1 @@ -1,6 +1,6 @@ -.\" generated with Ronn-NG/v0.9.1 -.\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "GIT\-REPL" "1" "September 2024" "" "Git Extras" +.\" generated with Ronn-NG/v0.10.1 +.\" http://github.com/apjanke/ronn-ng/tree/0.10.1 +.TH "GIT\-REPL" "1" "January 2026" "" "Git Extras" .SH "NAME" \fBgit\-repl\fR \- git read\-eval\-print\-loop .SH "SYNOPSIS" @@ -31,6 +31,16 @@ Equivalent of 'git ls\-files'\. exit|quit|q .P Ends the repl session\. +.SH "CONFIGURATION" +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 +.P +You can specify the prefix for the prompt (default \fBgit\fR): \fBgit config \-\-global git\-extras\.repl\.prefix ""\fR +.P +You can have the name of the current git repo shown in the prompt (default \fBfalse\fR): +.P +\fBgit config \-\-global git\-extras\.repl\.show\-project\-name "true"\fR .SH "EXAMPLES" .nf $ git repl diff --git a/man/git-repl.html b/man/git-repl.html index 3f9750e..d67ba2c 100644 --- a/man/git-repl.html +++ b/man/git-repl.html @@ -1,8 +1,8 @@ - - + + git-repl(1) - git read-eval-print-loop