2

I'm aware of this question Equivalent of PSReadLine for bash

But sadly it is still not close enough for me, all of the suggestions requires to press either tab, or ctrl + r or whatever, while Powershell made it really simple, just type and you see a list, keep typing to filter more, if you found a matching history command, just press down !

That's it.

Here is a video

l

EDIT: I already tried all the suggestions in the question mentioned.

I also tried again the solution by @Marcus Müller, and the result still the same, no history suggestion, just auto complete.

Here is another video: l

EDIT 2:

This is when I try fish, while this is the closest thing to what I want, I want it to be automatically shown. enter image description here

7
  • 2
    by the way, this is a good point in time to upgrade to the newer long-term release of Ubuntu. 24.04LTS. Commented Jun 23 at 13:01
  • fish shell can do this. Commented Jun 23 at 13:44
  • @OliverKnodel fish was the closest thing, but you have to click Ctrl + R to see history recommendation, I want it to be automatically shown once I start typing, I will add another video to my question
    – Nour
    Commented Jun 23 at 14:33
  • @Nour that is autosuggestions fishshell.com/docs/current/interactive.html#autosuggestions Commented Jun 23 at 14:40
  • @OliverKnodel hmm, it seems that it is enabled by default, yet I don't see a list of commands when I type echo for instance, check the last video I shared above. am I missing anything?
    – Nour
    Commented Jun 23 at 15:08

1 Answer 1

1

Not aware of any bash scripts that do that; I think bash's abilities to customize what is shown are limiting there.

But honestly, you're a user coming from Windows, nothing forces you to use bash; you can use the more feature-complete zsh (install via apt install zsh, as you seem to be on Ubuntu); scripts can still be run with bash, but you can make your default interactive shell zsh. And for zsh, there's quite popular plugins that do things that you describe!

I'd set this all up in one fell swoop, including the whole oh-my-zsh plugin bundle, because I bet the next thing you ask is how to get autocompletion for git, or a more information-rich prompt. So here I go:

#!/bin/bash
# This is done in bash; we'll switch to zsh when we're ready
# install dependencies: zsh and git.
sudo apt install -y zsh git

# Get the oh-my-zsh plugins and copy over the example zsh config
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

# clone the zsh-autocomplete plugin
git clone https://github.com/marlonrichert/zsh-autocomplete.git ~/.oh-my-zsh/plugins/zsh-autocomplete

# add the plugin to .zshrc:
sed -i 's/plugins=(/&zsh-autocomplete /' ~/.zshrc

When you then start zsh, it should give you a pretty dialog below your command line, where when you see something you like, you select it with the down-arrow. If you like to customize that dialog a bit (e.g. restrict to history etc), that's also easy, but I'll refer to the README of zsh-autocomplete for that :)

If this is close enough to what you want to work with everyday, you can make zsh your default shell by running chsh -s $(which zsh).

Also, I'd encourage you to try out other themes than the default one ("robbyrussel", you will find the corresponding line in your .zshrc), and look whether other zsh plugins offer features you want. I don't use many ((git tmux), actually), because I find the autocompletion that I get is good enough, and don't think making me type less characters when I want to pip install something is worth memorizing the shorter commands.

Update by Nour:

I figured out how to get the desired behavior with the suggestion of this answer and I wanted to select it to be the right answer so I'm adding the extra steps I did:

on top of all mentioned above, you need to add those commands to ~/.zshrc before the source $ZSH/oh-my-zsh.sh line.

zstyle ':autocomplete:*' default-context history-incremental-search-backward
zstyle ':autocomplete:*' min-input 1
setopt HIST_FIND_NO_DUPS
  • The first one will make the command history the default list (widget).
  • The second will make the minimum character you need to type to see the list of commands to 1 so you don't get the list all the time before you even type.
  • The third one to remove duplication if your history has the same command duplicated.

Here is a demo for the results: enter image description here

10
  • I mentioned that question because I tried all the suggestions including zsh, fish, fzf ..etc, none of them did the same trick for me. I will try your suggestion if it is different from the ones in that question, will let you know. thanks
    – Nour
    Commented Jun 23 at 13:49
  • I tested this on a Ubuntu 22.04 container. Looks like it works for me ;) Commented Jun 23 at 13:50
  • Genrally, when you've tried things, mention them in the question. One can write much shorter answers if one knows what didn't work. Commented Jun 23 at 13:51
  • My bad, I assumed mentioning "all of the suggestions requires to press either tab, or ctrl + r or whatever" would be suffice. Thank you for taking the time to write this though.
    – Nour
    Commented Jun 23 at 14:03
  • 1
    I don't mind; quite the contrary! I fixed up your modification of the oh-my-zsh code to go into your ~/.zshrc, because that won't get overwritten. Commented Jun 23 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .