Search code examples
amazon-web-servicesamazon-ec2command-line-interface

When pasting or paging through commands on EC2 CLI, the command gets corrupted and overlaps


Ok, sorry for the confusing title. Really struggling to figure out how best to describe this issue.

I manage multiple EC2 servers, all of them run AL2023 and I work from a Mac using the standard terminal.

Generally, just typing commands, no issues, regardless of the length of the command. The problem comes if I paste in a command, or move back through a command with cursor to make a correction, or use the up arrow to scroll through historical commands. After a few cursor presses, it's like the command gets moved about 11 characters to the right, and in that space the first 11 characters of the previous command gets stuck there. Doesn't affect the command from running correctly, but makes it an absolute pain to edit a command.

Sample terminal output

In the image above, less /etc/s was from a previous command that I scrolled up past using the up arrow. cd /var/www/prd/laravel is my actual command. If I hit enter, it will work. If I scroll up again, I'll get the next command, but still with less /etc/s at the start.

Anyone come across this (and more importantly, solved it)??

TIA SO!


Solution

  • Thanks to John in the comments for pointing me to SuperUser. Found the answer pretty quickly. To help anyone else stumbling on this thread, it had nothing to do with the boxes being AL2023 boxes or EC2 or anything like that. It was due to me customizing the prompt and using non-printing characters to set the color. These needed to be escaped. Answer I referenced is here:

    https://superuser.com/questions/186084/how-do-i-stop-my-bash-terminal-from-prepending-parts-of-previous-commands-to-my