How to enable Up/Down Arrow keys completion history for ash shell

I understand that OW ships with ash as the default shell. I'd like to enable the up and down arrow keys when searching through my shell history with it. Is this possible?

With bash as the default shell, one can create /root/.inputrc containing the following to achieve this behavior:

"\e[A":history-search-backward
"\e[B":history-search-forward

(Googling for this is surprisingly difficult as hits seem to ignore the query word "ash" thinking it was intended to be "bash"!)

Hi!
Has bash a special search history feature? I can't remember atm.
I can use the Up/Down keys to search through my last typed commands.
But this history gets deleted after logout. Which actually not that bad. (security)
To make this history persistent, you need to recompile busybox with that feature enabled.

I too can use the arrow keys... I should have made it more clear that the behavior expected is an autocomplete when using the arrow key. For example, consider this history:

   0 pwd
   1 cd /root
   2 cd /etc/config/
   3 vim dhcp
   4 htop

If you start typing the cd command and then hit up arrow, it would go to the first instance of a command that started with a literal cd... the behavior you're talking about, and what is out-of-the-box: hitting up arrow after typing cd first would just go through the history, so first would be htop, then vim dhcp, then cd /etc/config

That what I am asking for make sense?

Ash is quite old. I'd say wait until toybox has a shell. My guess is when the shell arrives it will become release 1.0. Then hopefully an option on openwrt to replace busybox. Then toybox will evolve to be very good on small embedded devices ...

There's bash for OpenWrt too, you can even set it as a default shell.

It makes sense....but I've never seen this behavior anywhere...interesting to know that ash does that.

Let us know if you have success compiling the feature in.

1 Like

ctrl-R works.

Not sure what you mean... ctrl+r does nothing for me.

To the above, you will have to enable / build

CONFIG_BUSYBOX_CUSTOM=y
CONFIG_BUSYBOX_CONFIG_FEATURE_EDITING_SAVEHISTORY=y
CONFIG_BUSYBOX_CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y
CONFIG_BUSYBOX_CONFIG_FEATURE_REVERSE_SEARCH=y

but with an eye to the target device.

1 Like

Thanks for the replies, all. I don't care enough to rebuild... I can make due with functionality as-is.

@anomeome - Changed my mind... I noticed that if I use make menuconfig to navigate and enable customization, there are tons of defaults that get enabled. Is it sane for me to just edit .config and add those 4 lines you shared to get this?

Yes, I edit things into my config all the time, but I usually edit a configdiff and then regenerate the .config:

./scripts/diffconfig.sh > configdiff
vi configdiff
cp configdiff .config
make defconfig && make oldconfig
My current BUSYBOX alterations
CONFIG_BUSYBOX_CUSTOM=y
CONFIG_BUSYBOX_CONFIG_DIFF=y
CONFIG_BUSYBOX_CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
CONFIG_BUSYBOX_CONFIG_FEATURE_EDITING_SAVEHISTORY=y
CONFIG_BUSYBOX_CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y
CONFIG_BUSYBOX_CONFIG_FEATURE_PS_LONG=y
CONFIG_BUSYBOX_CONFIG_FEATURE_REVERSE_SEARCH=y
CONFIG_BUSYBOX_CONFIG_FEATURE_SHOW_THREADS=y
CONFIG_BUSYBOX_CONFIG_FEATURE_SUID=y
CONFIG_BUSYBOX_CONFIG_FEATURE_TOPMEM=y
CONFIG_BUSYBOX_CONFIG_FEATURE_TOP_INTERACTIVE=y
CONFIG_BUSYBOX_CONFIG_FEATURE_TOP_SMP_CPU=y
CONFIG_BUSYBOX_CONFIG_FEATURE_TOP_SMP_PROCESS=y
CONFIG_BUSYBOX_CONFIG_LSOF=y

1 Like

I tried that with just a few busybox options but when I compare the .config before to the new one just adding those 4 lines from your post above, there are tons of new lines and features introduced. Perhaps I am not doing it correctly?

So:

  1. Copy my saved config to .config
  2. ./scripts/diffconfig.sh > configdiff
  3. vim configdiff and add those 4 lines then save
  4. cp configdiff .config
  5. make defconfig && make oldconfig

Here is my saved config from step 1.
Here is my edited one adding those 4 lines from step 3.
Here is the output file after step 5.

If you diff the first from the third, you see tons of new options. Is that right?