MacBook – Terminal auto complete and arrow keys working incorrectly

keyboardmacbook proterminal

I am using Macbook Pro 2017 (with touch bar) with macOS Sierra.

When using terminal, the autocomplete adds a character.

For example, typing 'cd Des' + tab, I am expecting 'cd Desktop' autocomplete.

Instead, I get Desktop/k

At this stage, if I click backspace, the letter 'k' always remains. Only able to remove characters before 'k'. Example: Desktopk, Desktok and so on.

If I click left or right arrow keys, I get weird characters as follows:

Deskto^[[D^[[Ck

If I just click enter to get out of the above mess, followed by clicking up arrow to get the previous command (in this case cd Desktop), I get the following print out instead.

^[[A

Is there a way around this to get auto complete without the extra character and arrow keys to work properly (as in up arrow brings up previous commands and left/right works to move between characters)? Had no similar issues on my previous macbook pro 2015. Please assist.

Best Answer

The above issue was caused by using ksh shell which seems to be the default for my laptop. After switching it to bash shell, all the above issues have been resolved.