I've noticed recently in my terminal emulator that sometimes the <up> arrow to show previous commands is behaving very strangely. This is best illustrated with a repeatable example I've found:
ls
(This just makes sure there's some command in the history)
git --git-dir=$HOME/.configrepo/ --work-tree=$HOME status
(It doesn't matter what this command outputs)
Now if I press <up> my current command line changes to git --git-dir=$HOME/.configrepo/ --work-tree=$HOME status
, but if I press it again I get git --git-dls
.
Oddly, if I run this command it outputs the result of ls
, and the text before ls
cannot be edited. It's almost as if a fragment of the git command has become a part of the prompt. I originally suspected there were non-printing characters hiding somewhere in there but this happens even if I type out all the commands from scratch.
In the bash profile I have the prompt set as follows.
PS1='\e[0;32m\w\$ \e[0m'
In case it's relevant I'm using the macOS 11.4 Terminal application.