4

Microsoft added a neat feature in the 7.3.0 release of PowerShell called Predictive IntelliSense which autosuggests commands to enter as you type based on the history. Such a suggestion can be accepted simply by pressing the (right arrow) key.

Predictive IntelliSense description

Predictive IntelliSense example

Can a similar effect be achieved in Ubuntu's Bash? I do know I could use Ctrl+R, but it does not seem as convenient.

adanski
  • 157

3 Answers3

6

There is a replacement for the built-in Ctrl + R called hstr. It allows you to search command history, matching all search tokens at the same time (among other things), and cycle through the results using arrow keys. Here is a short demonstration screen-cast that can also be viewed from hstr :

enter image description here

About:

Easily view, navigate and search your command history with shell history suggest box for bash and zsh.

HSTR is included in Ubuntu 21.10 and newer releases. To install run:

sudo apt update
sudo apt install hstr

To Install HSTR on Ubuntu 21.04 and older, run:

sudo add-apt-repository ppa:ultradvorka/ppa
sudo apt-get update
sudo apt-get install hstr

Then configure hstr for bash :

hstr --show-bash-configuration >> ~/.bashrc
source ~/.bashrc

And then use Ctrl + R

stumblebee
  • 4,379
4

As also suggested by @muru in a comment, there is the ble.sh ―Bash Line Editor― that can do what you want. Before installing it, you have to install its dependencies (if not already installed): git, make (GNU make), and gawk (GNU awk). You can do that with the following command:

sudo apt install git make gawk

Then, to install ble.sh run the following commands:

git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh install PREFIX=~/.local
echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc

The above commands will download the repository in your current directory, install it in ~/.local/share/blesh/ble.sh and add the required line in your ~/.bashrc.

After that close and reopen your terminal and you should have autosuggestions enabled:

terminal showing autosuggestions

If you want to uninstall ble.sh, follow these steps (from the project's 1.6 Uninstall section):

  • Close all the ble.sh sessions (the Bash interactive sessions with ble.sh)

  • Remove related user data. If you would like to keep them, you can skip these steps.

    • Remove the added lines in .bashrc.
    • Remove blerc files (~/.blerc or ~/.config/blesh/init.sh) if any.
    • Remove the state directory ~/.local/state/blesh if any.
  • Remove the directory where ble.sh is installed. When you use out/ble.sh inside the working tree of the git repository, the installed directory is the directory of the repository. When you use ble.sh installed by make install, the installed directory is <PREFIX>/share/blesh where <PREFIX> (default: ~/.local) is the prefix specified to make install in the installation stage. When you use the version extracted from a tarball, the directory created by extracting the tarball is the installed directory.

  • Remove the cache directory ~/.cache/blesh if any.

  • Remove the temporary directory /tmp/blesh if any [ Only needed when your system does not automatically clears /tmp ].

2

I think using fish might help you with this. sudo apt install fish

then open terminal right click on it and go to preferences -> Command -> Enable Run a custom command instead of shell

and write fish in below input. Restart terminal and you're good to go :)