-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add persistent history to git-repl
#1226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
jjb
commented
Jan 18, 2026
- persistent command history
- notes
|
@spacewander @hyperupcall take a look |
|
i have comments in the code discussing different approaches we could take |
spacewander
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will vote for write command to history in all cases except for blank. Non-git command may be important to record.
bin/git-repl
Outdated
| # global history for all projects. we could make option for per-project history | ||
| # for my use, i want this global history, and it's also much more simple to implement | ||
| # name is analogous to bash_history and zsh_history | ||
| HISTFILE=~/.git_repl_history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to make it configurable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay take a look at what i came up with
|
i'll wait for default command to merge before bringing main into this one |
|
@hyperupcall wdyt? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for tackling this! When I saw the previous history -s, I saw room for improvement.
Everything looks really great, I was hoping to tweak mainly just two things:
- Use
HISTIGNOREto replace some manualifs - Tweak
HISTFILElocal and filename (reasoning in review comments)
Mentioned in the review comments, git-extras.repl.init-eval could later be introduced in the future so that HISTCONTROL, etc. could be changed directly be the user.
| if [[ "$use_local_history" == "true" ]]; then | ||
| HISTFILE="$(git rev-parse --show-toplevel)/.git_repl_history" | ||
| else | ||
| HISTFILE=~/.git_repl_history |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| HISTFILE=~/.git_repl_history | |
| HISTFILE=${XDG_STATE_HOME:-$HOME/.local/state}/git_extras_repl_history |
Mostly conform to the XDG Base Directory Specification so users' home directories don't get cluttered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting, i don't know anything about this - does it need discussion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussing further is an option!. But syntax is pretty standard for Bash and implements this part:
$XDG_STATE_HOMEdefines the base directory relative to which user-specific state files should be stored. If$XDG_STATE_HOMEis either not set or empty, a default equal to$HOME/.local/stateshould be used.The
$XDG_STATE_HOMEcontains state data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in$XDG_DATA_HOME. It may contain:
- actions history (logs, history, recently used files, …)
- current state of the application that can be reused on a restart (view, layout, open files, undo history, …)
Another option is to write HISTFILE=${XDG_STATE_HOME:-$HOME/.local/state}/git-extras/repl_history. That might be better if there's other similar files that need to be written under $XDG_STATE_HOME.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i meant, discussion amongst maintainers - i'm happy with whatever you/y'all decide
| 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; 'quit', 'exit', 'q', ^D, or ^C to exit the git repl." | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| HISTIGNORE=${HISTIGNORE:-+([[:space:]])} |
More details on line 50,. Be sure to add shopt -s extglob at the top of the file, this depends on the +() syntax!
| # History | ||
| history -s "$cmd" | ||
| # Add command to history if it is not all whitespace | ||
| if [[ ! "$cmd" =~ ^[[:space:]]*$ ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use HISTIGNORE like above instead of adding this condition.
|
|
||
| Commands entered in a repl session will be saved to a history file and be available in | ||
| future sessions, similar to a shell or programming language repl. By default, | ||
| there is one global history file, ~/.git_repl_history. You can specify that your projects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| there is one global history file, ~/.git_repl_history. You can specify that your projects | |
| the global history file is at `~/.local/state/git_extras_repl_history`. You can specify that your projects |
man/Commands.md may need to be regenerated,.
| fi | ||
|
|
||
| # file doesn't exist, is empty, or contains only whitespace | ||
| if [[ ! -f "$HISTFILE" ]] || [[ ! -s "$HISTFILE" ]] || ! grep -q '[^[:space:]]' "$HISTFILE"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if [[ ! -f "$HISTFILE" ]] || [[ ! -s "$HISTFILE" ]] || ! grep -q '[^[:space:]]' "$HISTFILE"; then | |
| if [[ ! -f "$HISTFILE" ]] || [[ ! -s "$HISTFILE" ]]; then |
Is [[ ! -f ...]] || [[ ! -s ... ]] enough? I think the grep is a bit too defensive, having trouble thinking when that condition would hold.
Curious what version of bash you are on? bash 5.2.37 seems to have fixed the empty file & history -r/history -a thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫠
➔ bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)
Copyright (C) 2007 Free Software Foundation, Inc.
➔ type bash
bash is /bin/bash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see! Might be good to add the version with the history -r... comment so someone with a future version doesn't change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, added a comment 79f4f72
Co-authored-by: Edwin Kofler <edwin@kofler.dev>
Co-authored-by: Edwin Kofler <edwin@kofler.dev>
|
thanks @hyperupcall - for the |
|
@jjb It's up to you! I couldn't suggest some things, like adding the |
|
@hyperupcall you have write access on my branch, go for it |