Semantic terminal: AI generator of one-liners based on natural language description

This note is inspired by the article I replaced Google with 50 lines of Python. A month later, I forgot how to write tar -xzf. At some point, after hitting Alt+Tab to switch to the browser again to quickly find some Linux one-liner, I thought I had enough of this and went looking for the mentioned article. After rereading it and browsing the comments, I realized that some things I needed were not done quite as I would like, so I went to build my own bike. So, I present to you semantic-terminal:

  • Installed via pip: pip install semantic-terminal

  • Unix-style utility sem that passes arguments to the LLM with the prompt: “Make a one-liner”

  • Optionally provides a detailed description of the one-liner in the request language

  • Optional utility sem-run, which runs the generated command while saving it in the terminal history

  • Generation delay of less than 1 second provided that ... ahem ... stable internet

Motivation

I mainly work in Linux; the terminal is one of my main tools, but still, mostly it consists of ls, mkdir, cd, git, grep, htop, ssh, and maybe a dozen more commands. I don’t remember all possible parameters/options, and to be honest, I don’t want to/can’t remember. Generally, it is customary for each such utility to have a --help option, which tells and suggests. Unfortunately, even with --help, there is still a large amount of what can be done with the system that remains unknown. I’m sure there are people who know most of the depths of Unix-like systems, but I am not one of them. For a long time, in cases where I don’t remember how to do something in the terminal, I just open Google and search for the needed one-liner. With the emergence of terminals like Claude Code or OpenCode, there has been the ability to do the same thing directly in the terminal, and I must say I actively use it (and I’m definitely not the only one). However, I still use the regular terminal a lot and do not intend to completely abandon it in favor of AI terminals, so I want a unix-style command that would perform a Google/SO search, especially since it is clear that this is not difficult to implement.

Why didn’t I take something ready-made?

The solution from the author of the article: I replaced Google with 50 lines of Python. A month later, I forgot how to write tar -xzf, which is good, but it seemed a bit underdeveloped to me personally. The alternatives mentioned in the comments (and what I found myself) are mostly some more general solutions in the context of AI terminals, but I wanted a unix-style: a command that does exactly one thing.

What did I get?

So, with all this, I opened my laptop, started coding, launched the AI terminal, described the task, and went to drink tea while watching silly YouTube videos, periodically checking what was happening. In the end, we have a Python package semantic-terminal: it installs via pip and provides a single command sem, here’s its essence:

sem     # Generate a command
sem -r  # Generate and execute a command
sem -v  # Generate and explain a command
sem ! or sem -r     # Execute the generated command
sem ?                # Print the generated command again

Under the hood, there’s a simple idea: when running in generation mode, we simply feed the description to the LLM with the instruction “Make a one-liner command,” the rest is for convenience.

Two key features

Overall, I appreciated the 50-line script: minimalist, only what is needed. However, it still had two significant problems for me and one minor one. I’ll start with the minor one: I personally don’t like interactivity and preferred to make the interface in the form of two modes: generation and execution. Now, regarding the significant problems.

The first is that the generated command is executed in a child process, and there’s nothing that can be done about it within Python. As a result, the executed command doesn’t get into the terminal history, and accordingly, we can’t quickly reproduce or find it in history. To work around this, I added a wrapper in bash/powershell sem-run, which can be optionally installed through sem-setup.

The second problem is that besides the command itself, sometimes it's also nice to understand it—so I added the --verbose mode, which generates not only the command but also its explanation. There's an immediate pleasant bonus: most modern LLMs are multilingual, so it's easy to get a description in the same language as the request out of the box. I tested it in Russian, English, Chinese, and Spanish.

Quick Start

Install from PyPI

pip install semantic-terminal

First, you need to configure the LLM. The simplest (and fastest) thing I've found so far is to register a free Groq account https://console.groq.com, get the API key, and run

sem config set api_key

after which you paste the account key. For complete configuration, see the README. If you want to save the executed commands in the terminal history, then run

sem-setup

And use sem-run to execute commands, not sem -r/sem !. That's basically it; now we are ready!

Examples

There will be one example, but with different options: “sem show last 10 commits”. First, the option using sem !

$ sem show last 10 commits
$ git log -n 10 --oneline
$ sem !
$ git log -n 10 --oneline
3111e16 (HEAD -> main, tag: v1.2.0, origin/main) Feat/remove OpenAI (#2)
96d6f59 v1.0.1
918daad Test/workflow (#1)
95ce22b (test/number_of_lines) Test number of lines badge
97ad729 [AI] Vibecoded by Claude Opus 4.6
$ history 5
  368  sem !
  369  history
  370  sem show last 10 commits
  371  sem !
  372  history 5

As you can see, in the history sem !. And here’s the option with sem-run:

$ sem show last 10 commits
$ git log -n 10 --oneline
$ sem-run
$ git log -n 10 --oneline
3111e16 (HEAD -> main, tag: v1.2.0, origin/main) Feat/remove OpenAI (#2)
96d6f59 v1.0.1
918daad Test/workflow (#1)
95ce22b (test/number_of_lines) Test number of lines badge
97ad729 [AI] Vibecoded by Claude Opus 4.6
$ history 3
  384  sem show last 10 commits
  385  git log -n 10 --oneline
  386  history 3

And, accordingly, examples from the repository. In Russian:

$ sem -v show the last 10 commits as a tree
To show the latest commits as a tree, you can use the git log command with the --graph option. Here's what this command does:
* Displays the latest commits as a tree, where each branch is represented by a separate line
* The --graph option allows you to visualize the commit history
* The -10 option limits the output to the last 10 commits
* The git log command is used to view the commit history
git log --graph -10

In Chinese:

$ sem -v Show 10 commits using tree
To display 10 commit records, you can use the git log command along with the --oneline and --graph options to show the commit history in a tree structure. Here are the key points:
* The git log command is used to display the commit history
* The --oneline option makes each commit record display only one line
* The --graph option shows the commit history in a tree structure
* The --all option displays commit records from all branches
* Using the head option can limit the number of commit records displayed
git log --graph --oneline --all -10

And in Spanish:

$ sem -v Show 10 commits with the tree
To show 10 commits with the tree, you can use the git log command with the --oneline and --graph options. Here are some key points about this command:
* The git log command is used to display a log of commits.
* The --oneline option displays each commit on a single line.
* The --graph option shows the commit tree.
* The -10 option limits the output to the last 10 commits.
* This command assumes you are in the root directory of a git repository.
git log --oneline --graph -10

And I would like to note separately that all of this works quite swiftly (model llama-3.3-70b-versatile, hosted on Groq, the FSB is not actively testing anything), the demo is edited without changing the speed and without cuts between executing the command and getting the result.

In general, enjoy it! If you liked it, don’t forget to upvote the article and star the repository, it will make the author very happy!

Comments

    Also read