How to enable Android adb shell history with up / down keys in under Linux?
Asked Answered
O

3

12

I recently upgraded to the new Android SDK and I noticed something very very bothering. It seems it is no more possible to use the command history in the shell. Are you noticing the same? The Android shell seems horrible to me, but at least, in the last SDK, I had the command history. Now, it seems that pressing the up/down arrow, result in some codes written on the prompt (something like ^[[A, ^[[B etc...). I tried to read a little bit around but I found very few asking this a zero answers. Any idea why this happens and how to solve this?

Orit answered 18/12, 2010 at 13:30 Comment(1)
Luckily not the case anymore in Android 7 (and likely earlier).Peloquin
C
4

You can run the shell inside rlwrap:

rlwrap adb shell

I prefer to run it in an Emacs shell buffer myself, I recommend this if you're not allergic to Emacs. Emacs is also nice for running adb logcat: you get a searchable history and the messages are updated as they come, and you can easily put interesting patterns in color (M-x highlight-regexp and friends).

Croquette answered 18/12, 2010 at 15:48 Comment(3)
I tried the command you gave me but I see no changes. The shell is exactly identical. Maybe I did something wrong? Thanks!Orit
@Luca: I get basic command line edition with adb and the emulator from the Gingerbread SDK under Linux, and rlwrap gives be readline edition. I do seem to recall rlwrap not working with a previous SDK version, but I don't remember which version.Southsoutheast
I can't understand... I just tried it again but I really see no changes.Orit
I
1

If you're talking about real device (not emulator), you should try some non-official firmwares, such as Cyanogenmod - it includes much better binary tools, such as much more featureful shell, sane set of regular UNIX tools, ssh server, etc.

If you're talking about emulator, you can extract these binaries from firmwares and push it into emulator as is (using a memory card image).

Iambic answered 18/12, 2010 at 21:53 Comment(4)
I'm talking about a real device and this issue is not related to the firmware. It started when I upgraded to the last SDK 2.3 on the same device.Orit
Anyway I just checked and it is happening on the emulator as well.Orit
Ok, I understand. Well, at least you can try connecting using ssh (i.e. dropbear ssh server at your device and ssh client from your development box) as a workaround.Iambic
I don't know if the benefits of this workaround may justify the effort... I flash the device very often... Is it simple to port the server to Android? How do I recompile it? Thanks!Orit
H
0

If Ctrl-p still gives you previous history entries, then it's possible that the arrow keys became unbound for some reason. Try this:

bind '"\e[A": previous-history'
bind '"\e[B": next-history'

If that makes the arrow keys work, you can make it persistent by adding these two lines to /etc/inputrc or ~/.inputrc:

"\e[A": previous-history
"\e[B": next-history
Hinman answered 18/12, 2010 at 15:9 Comment(3)
Last I used it the Android shell didn't use readline, but then I don't remember it providing any form of command line edition including arrows for history.Southsoutheast
@Gilles: I haven't used it in quite a while myself, but I was just basing my answer on what the OP said.Hinman
Ctrl-P gives me the history but not in the Android shell. But, where do I have to try the bind command? In the Linux shell? I tried there and it makes it impossible to use the arrows to move in the history. If I try in the Android shell, the command bind seems not to exist. Any idea?Orit

© 2022 - 2024 — McMap. All rights reserved.