DEV Community

Thompson Olufemi
Thompson Olufemi

Posted on

cmdlib: Save, Search and Run Terminal Commands with Descriptions (Better Than CTRL+R)

If you use the terminal a lot, you probably run into this problem.

You ran a useful command some time ago. Maybe last week or last month. Now you need it again but you cannot remember the exact command.

So you press CTRL+R and start searching through your shell history.

Sometimes you find it quickly. Many times you don't. Or you remember what the command does but you do not remember the exact text of the command.

This happens to me all the time.

For example I might remember something like

"that command that deletes docker images"

or

"that command that finds large files in a folder"

But when I search with CTRL+R it does not help because I do not remember the exact command text.

So I built a small tool for myself called cmdlib.

cmdlib is a very simple idea.

It lets you save commands with a description and later search using that description.

For example you can write a command like :

docker image prune -a

And then add a meaninful description :

delete unused docker image

Later when you forget the command you can just search :

delete docker

and cmdlib will show it.

You can then press Enter and run it directly.

So it works like a personal command library for your terminal.

You can save commands you use often. You can add a small description so you remember what they do. Then you can search them anytime.

Some things you can do with cmdlib :

  • Save useful commands with descriptions
  • Search commands using normal words
  • Run the command directly from the search results
  • Delete commands you no longer need
  • Browse your shell history and save commands from there

The workflow is very simple.

Install it by running the following command in your terminal.

npm install -g cmdlib

Then After installing,

  • restart your terminal
  • or run source ~/.bashrc if using bash shell
  • or run source ~/.zshrcif using zsh shell

Then type cmdlib in your terminal to start using it.

Once you run it, it opens a small interactive search interface in your terminal where you can search, save, and run commands easily.

It is a small tool, but it has been very useful for me because I no longer forget commands that took time to figure out.

If you want to try it, you can install it from npm.

npm install -g cmdlib

You can also checkout the README on the GitHub page for instructions on how to use it:

https://github.com/olufemithompson/cmdlib

If you find it useful, please consider giving the repo a star on GitHub. It helps others discover the project.

If you try it and have suggestions or ideas for improvements, I would love to hear them. Contributions and feedback are always welcome.

Top comments (0)