3

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
  • 147
  • 1
    fzf is really neat but if you don't like pressing CTRL+R, are you open to using zsh instead of bash? zsh-autosuggestions looks really similar and if you're not familiar then you can probably see it in use on some newer kali linux tutorials or video demos that show the terminal as zsh with the autosuggestions has been the default on kali for the past few years now. – mchid Nov 25 '23 at 05:18
  • 3
    This feature is also seen in fish, and zsh-autosuggestions mentioned by @mchid is inspired by the fish one (I use it but it's not some "predictive intelligent" thing, it just shows the most recent command from history matching what you have typed so far) https://unix.stackexchange.com/a/646375/70524 suggests https://github.com/akinomyoga/ble.sh does the same for bash – muru Nov 26 '23 at 10:14

3 Answers3

5

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
  • 3,547
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 ].

  • 1
    For the highlighting style for the suggested text, you may also check the Q&A at https://superuser.com/questions/1512618. – akinomyoga Nov 27 '23 at 06:25
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 :)