From 5ca936010914a10a4566c94290be29349955d842 Mon Sep 17 00:00:00 2001 From: wyattscarpenter Date: Sun, 22 Sep 2024 20:22:58 -0700 Subject: [PATCH] Enhance `git-repl` (#1160) --- Commands.md | 12 ++++++----- bin/git-repl | 33 ++++++++++++++++++++---------- man/git-repl.1 | 50 +++++++++++++++------------------------------- man/git-repl.html | 51 ++++++++++++++++++++++++++--------------------- man/git-repl.md | 21 +++++++++++-------- 5 files changed, 87 insertions(+), 80 deletions(-) diff --git a/Commands.md b/Commands.md index 4ea5520..9fc626e 100644 --- a/Commands.md +++ b/Commands.md @@ -375,14 +375,16 @@ Git read-eval-print-loop. Lets you run `git` commands without typing 'git'. Commands can be prefixed with an exclamation mark (!) to be interpreted as a regular command. -Type `exit` or `quit` to end the repl session. +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. ```bash $ git repl -git version 2.9.2 -git-extras version 3.0.0 -type 'ls' to ls files below current directory, -'!command' to execute any command or just 'subcommand' to execute any git subcommand +git version 2.34.1 +git-extras version 7.3.0 +Type 'ls' to ls files below current directory; '!command' to execute any command or just 'subcommand' to execute any git subcommand; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl. git (master)> ls-files History.md diff --git a/bin/git-repl b/bin/git-repl index f9996f6..a136879 100755 --- a/bin/git-repl +++ b/bin/git-repl @@ -2,7 +2,7 @@ git version echo "git-extras version ""$(git-extras -v)" -echo "type 'ls' to ls files below current directory, '!command' to execute any command or just 'subcommand' to execute any git subcommand" +echo "Type 'ls' to ls files below current directory; '!command' to execute any command or just 'subcommand' to execute any git subcommand; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl." while true; do # Current branch @@ -10,16 +10,28 @@ while true; do # Prompt if test -n "$cur"; then - prompt="git ($cur)> " + cur_string=" ($cur)" else - prompt="git> " + cur_string="" fi + if test -n "$exit_status" && test "$exit_status" -ne 0; then + es_string=$' \e[31m['"$exit_status"$']\e[0m' + else + es_string="" + fi + prompt="git$cur_string$es_string> " - # Readline - read -e -r -p "$prompt" cmd - - # EOF - test $? -ne 0 && break + # Use arguments as a command if any are provided. + if [ $# -ne 0 ]; then + cmd=$* + set -- + echo "$prompt" "$cmd" # It is as though you had entered a command. + else + # Readline + read -e -r -p "$prompt" cmd + # Check for EOF, and end the program if so (handles ^D). + test $? -ne 0 && break + fi # History history -s "$cmd" @@ -28,16 +40,17 @@ while true; do case $cmd in ls) cmd=ls-files;; "") continue;; - quit|exit) break;; + quit|exit|q) break;; esac if [[ $cmd == !* ]]; then - eval ${cmd:1} + eval ${cmd:1} elif [[ $cmd == git* ]]; then eval $cmd else eval git "$cmd" fi + exit_status=$? done echo diff --git a/man/git-repl.1 b/man/git-repl.1 index b3040f2..b3721f4 100644 --- a/man/git-repl.1 +++ b/man/git-repl.1 @@ -1,56 +1,42 @@ -.\" generated with Ronn/v0.7.3 -.\" http://github.com/rtomayko/ronn/tree/0.7.3 -. -.TH "GIT\-REPL" "1" "October 2017" "" "Git Extras" -. +.\" 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" .SH "NAME" \fBgit\-repl\fR \- git read\-eval\-print\-loop -. .SH "SYNOPSIS" \fBgit\-repl\fR -. +.P +\fBgit\-repl\fR [command\|\.\|\.\|\.] .SH "DESCRIPTION" -Git read\-eval\-print\-loop\. Lets you run \fBgit\fR commands without typing \'git\'\. -. +Git read\-eval\-print\-loop\. Lets you run \fBgit\fR commands without typing 'git'\. .P -Commands can be prefixed with an exclamation mark (!) to be interpreted as a regular command\. -. +Commands can be prefixed with an exclamation mark (!) to be interpreted as a regular shell command\. .P -Type \fBexit\fR or \fBquit\fR to end the repl session\. -. +Any arguments to git repl will be taken collectively as the first command to execute in the repl\. +.P +Type \fBexit\fR, \fBquit\fR, or \fBq\fR to end the repl session\. Ctrl\-D and Ctrl\-C will also work\. .SH "COMMANDS" -. .P Interpreted as \fBgit \fR\. -. .P ! -. .P Interpreted as \fB\fR (not through \fBgit\fR)\. -. .P ls -. .P -Equivalent of \'git ls\-files\'\. -. +Equivalent of 'git ls\-files'\. .P -exit|quit -. +exit|quit|q .P Ends the repl session\. -. .SH "EXAMPLES" -. .nf - $ git repl -git version 2\.9\.2 -git\-extras version 3\.0\.0 -type \'ls\' to ls files below current directory, -\'!command\' to execute any command or just \'subcommand\' to execute any git subcommand +git version 2\.34\.1 +git\-extras version 7\.3\.0 +Type 'ls' to ls files below current directory; '!command' to execute any command or just 'subcommand' to execute any git subcommand; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl\. git (master)> ls\-files History\.md @@ -67,14 +53,10 @@ git (master)> !echo Straight from the shell! Straight from the shell! git (master)> quit -. .fi -. .SH "AUTHOR" -Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR> -. +Written by Tj Holowaychuk <\fItj@vision\-media\.ca\fR>\. Updated by Wyatt S Carpenter to add display of the previous command's exit status, 'q', and the ability to pass in the initial command as arguments\. .SH "REPORTING BUGS" <\fIhttps://github\.com/tj/git\-extras/issues\fR> -. .SH "SEE ALSO" <\fIhttps://github\.com/tj/git\-extras\fR> diff --git a/man/git-repl.html b/man/git-repl.html index f24f7ce..3f9750e 100644 --- a/man/git-repl.html +++ b/man/git-repl.html @@ -1,8 +1,8 @@ - - + + git-repl(1) - git read-eval-print-loop