1
$ xelatex

Command 'xelatex' not found, but can be installed with:

sudo apt install texlive-xetex

If a binary not found but apt knows the package associated with, it would recommend the installation command.

When the recommend prompts, is there an easy shortcut or command like maybe instllaptrecommend so that I can skip copy/paste to directly execute the installation command?

Rahn
  • 81

2 Answers2

0

Usually you have to run the needed installation command manually. The requested functionality does not exist. For clues see source code of main command-not-found python script and file list of command-not-found package.

We can invent some hack like two functions shown below

install_cnf_apt() { $1 2>&1 | grep -E "(apt|apt-get).*install" | tail -n1 | sh -x; }
install_cnf_snap() { $1 2>&1 | grep "snap install" | tail -n1 | sh -x; }

and add them to ~/.bashrc later. They will work as shown below:

$ htop

Command 'htop' not found, but can be installed with:

sudo snap install htop # version 3.0.5, or sudo apt install htop

See 'snap info htop' for additional versions.

$ install_cnf_apt htop
+ sudo apt install htop
...
Unpacking htop (2.1.0-3) ...
Setting up htop (2.1.0-3) ...
...

or

$ install_cnf_snap htop
+ sudo snap install htop
htop 3.0.5 from Maximiliano Bertacchini (maxiberta) installed
N0rbert
  • 99,918
0

I figured out bit shorter version

function rui() { $1 2>&1 | bash;}

rui abbreviation for run install

Use:

rui xelatex

However, this is useful only if you know the program is not installed. You should not run it if the program is already installed. And it can not cope with more than one recommendation. It will simply run all of them...

As mentioned by @N0rbert you can add such functions to /home/username/.bash_aliases to make them persistent

With this line, you can make it persistent and immediately available for use:

echo "function rui() { \$1 2>&1 | bash;}" >> /home/$USER/.bash_aliases && source ~/.bashrc