7

Is there any feature in a terminal to make a list of favorites commands, using shortcuts, or some type of utility, something integrated into the terminal?

1

7 Answers 7

8

You can define aliases:

alias l='ls -al'
alias tlc='toolongcommand'

(you can put that into your .bashrc)

and you probably know about tab completion (if you never heard of that, I can imagine why you are asking).

3
  • 1
    is it possible to use a file called .favorites for example? I don't want to mix functions in .bashrc with my favorites.
    – danilo
    Jun 23, 2021 at 22:44
  • 3
    You can include another file from your .bashrc with the source command, in this case source .favorites. Unlike calling it without source, this executes the content in the context of the current shell which is important here; otherwise you'd call it, add the aliases to the new shell that you just called, that shell would exit, and the aliases would be immediately forgotten.
    – HuHa
    Jun 23, 2021 at 22:50
  • 9
    Instead of .favorites, better name it .bash_aliases. If present, that file gets sourced in .bashrc by default, at least on Ubuntu and is the default location to put user-defined aliases.
    – ojdo
    Jun 24, 2021 at 9:50
2

I would recommend HSTR (formerly known as history suggest box. HSTR (HiSToRy) is a command line utility that brings improved bash/zsh command completion from the history. It aims to make completion easier and more efficient than Ctrl-r.

HSTR can also manage your command history (for instance you can remove commands that are obsolete or contain a piece of sensitive information) or bookmark your favorite commands.

I use it in particular for saving favorites.

To install

sudo add-apt-repository ppa:ultradvorka/ppa && sudo apt-get update && sudo apt-get install hstr && hstr --show-configuration >> ~/.bashrc && . ~/.bashrc
1

In Bash those are functions

A Bash function is essentially a set of commands that can be called numerous times. The purpose of a function is to help you make your bash scripts more readable and to avoid writing the same code repeatedly. Compared to most programming languages, Bash functions are somewhat limited.

You can create a function "f1" that would execute a command with specific options and a function "f2" that does the same command with a 2nd set of default options.

1

If interested, you could also try different shell, fish.

Fish has great auto-completion by default. Commonly run (or favorite) commands can be tab completed quite easily. This is also a useful feature for figuring out command sequences you don't have memorized, but remember parts of. You can type a portion of the sequence and use the ↑ and ↓ keys to go through you command history.

# install fish
apt install fish

# command to enter the fish shell
fish

# if you want set fish as your default shell 
# (log out and back in for the change to take place
chsh -s /usr/bin/fish

# switch back to bash as default with
chsh -s /bin/bash

And like bash, you can create aliases in fish. A handy way to do it in the terminal:

alias command_name "your command"
funcsave command_name

The functions are located in $HOME/.config/fish/functions/

1
1

I'll vote for customing our terminal to let it learn which command used most frequently. And here the tips:

1.install zsh and set it as the default Shell environment.

# install `zsh`
sudo apt install zsh
# be sure `zsh` is installed successfully
which zsh
# set `zsh` as the default Shell
chsh -s /usr/bin/zsh

2.install Oh My Zsh

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

3.configure zsh theme(optional)

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

4.add zsh-autosuggestion

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

after the installation, we should set plugins=(git zsh-autosuggestions zsh-syntax-highlighting) in ~/.zshrc, then restart Shell.

5.install Terminator(optional)

sudo apt install terminator

\o/ finish! Just have a try, and you will love it!

And be friendly to your up, down, left, right keys.

1

It hasn't mentioned before here, but it might be useful to know that under bash by default command history is saved to ~/.bash_history and lines can be copied and saved out of here.

1

There is a small app called Marker that does exactly what you want. While your edited/polished command chain is on the command line you bookmark it with CTRL+k. It allows you to add some description too. to recall one of your bookmarked commands press CTRL+SPACE Type marker remove to remove a user-defined command

to install

git clone --depth=1 https://github.com/pindexis/marker ~/.marker && ~/.marker/install.py

main ref: https://github.com/pindexis/marker

also see this article for explanation.

The great thing about this app is that it offers almost all Linux commands -- including their flags and option -- as a template for you to complete. Just type the name of the command and press CTRL+SPACE.

You must log in to answer this question.

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