Improve your shell skills with Clai

Posted on Jan 24, 2024

I created a very simple command line utility in go that helps you create non-trivial command line / shell commands. It’s actually just a thin wrapper around the openai API’s, but it can be pretty usefull and saves you from switching to a chatgpt session or stackoverflow.


$ clai "group a tab separated file by first column, sum them by third column"
awk -F'\t' '{sum[$1] += $3} END {for(group in sum) print group, sum[group]}' file.txt

This command uses awk to read a tab-separated file, it creates an array 'sum' where the keys are the values in the first column and the values are the sum of the third column for each group. Finally, it prints the group and the sum.


$ clai "find the largest file"
To find the largest file in a directory and its subdirectories, you can use the `find` and `du` commands together:

find /path/to/directory -type f -exec du -sh {} + | sort -rh | head -n 1

This command will find all the files in the specified directory and its subdirectories, calculate their sizes using `du`, sort them in descending order, and display the largest file with its size.

It’s called CLAI - command line AI and it’s pretty configurable. By changing the system prompt you can basically make it do whatever you want - a realtime translation service, tweak it for PowerShell, etc.