Skip to content

Conversation

@jjb
Copy link
Contributor

@jjb jjb commented Jan 18, 2026

  • persistent command history
  • notes

@jjb
Copy link
Contributor Author

jjb commented Jan 18, 2026

@spacewander @hyperupcall take a look

@jjb
Copy link
Contributor Author

jjb commented Jan 18, 2026

i have comments in the code discussing different approaches we could take

Copy link
Collaborator

@spacewander spacewander left a 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
Copy link
Collaborator

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

Copy link
Contributor Author

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

@jjb
Copy link
Contributor Author

jjb commented Jan 20, 2026

i'll wait for default command to merge before bringing main into this one

@jjb jjb requested a review from spacewander January 20, 2026 05:20
@jjb
Copy link
Contributor Author

jjb commented Jan 20, 2026

@hyperupcall wdyt?

Copy link
Collaborator

@spacewander spacewander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@hyperupcall hyperupcall left a 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 HISTIGNORE to replace some manual ifs
  • Tweak HISTFILE local 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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_HOME defines the base directory relative to which user-specific state files should be stored. If $XDG_STATE_HOME is either not set or empty, a default equal to $HOME/.local/state should be used.

The $XDG_STATE_HOME contains 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.

Copy link
Contributor Author

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."

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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

Copy link
Collaborator

@hyperupcall hyperupcall Jan 24, 2026

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.

Copy link
Contributor Author

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

@hyperupcall hyperupcall changed the title persistent history Add persistent history to git-repl Jan 23, 2026
jjb and others added 2 commits January 24, 2026 13:19
Co-authored-by: Edwin Kofler <edwin@kofler.dev>
Co-authored-by: Edwin Kofler <edwin@kofler.dev>
@jjb
Copy link
Contributor Author

jjb commented Jan 24, 2026

thanks @hyperupcall - for the HISTIGNORE / shopt -s extglob stuff, i didn't understand if i could just accept your suggestions or need to make additional changes - do you want to just go ahead and make the changes?

@hyperupcall
Copy link
Collaborator

@jjb It's up to you! I couldn't suggest some things, like adding the shopt -s extglob to the top of the file. But for the things I was able to accept, you can click the "Accept suggestion"/"Commit suggestion" if you'd like, that's what I usually do when I'm getting reviewed.

@jjb
Copy link
Contributor Author

jjb commented Jan 24, 2026

@hyperupcall you have write access on my branch, go for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants