Shellm is a lightweight client for interacting with the Ollama API, written entirely in a single Bash script. It provides a simple interface to generate responses from language models, interact with custom tools, and integrate AI capabilities into everyday Linux workflows.
config.yaml
files according to XDG Base Dir spec. Add your own!shellm
Bash script to a directory of your choice, e.g., /usr/local/bin
.chmod +x /usr/local/bin/shellm
localhost:11434
or set the API_URL
environment variable to your specific endpoint.shellm "What is the weather like today?"
This will generate a response using the default model.
Option | Description |
---|---|
-u |
API URL (default: http://localhost:11434/api ) |
-m |
Model name (default: qwen2.5:3b-instruct-q5_K_M ) |
-n |
Number of predictions to generate (default: 200 ) |
-v [0-3] |
Log level (verbosity) mode for debugging |
-t |
Activate tool use, allowing Shellm to use and chain tools as specified in JSON configuration files. |
prompt |
The prompt for the model. If reading from stdin, this will prepend to the input. |
Generate a response to a simple question:
shellm "Why is the sky blue?"
Use a different model:
shellm -m "newmodel-v1:6b" "Summarize the plot of 'The Great Gatsby'."
Enable tool usage mode:
shellm -t "Translate the following text to French: 'Hello, how are you?'"
Shellm supports chaining multiple invocations, allowing the user to pass the output of one command as the input to the next. This is useful for refining AI responses or handling complex tasks:
response=$(shellm "What is the capital of France?")
shellm "Is $response a popular tourist destination?"
Shellm can be easily integrated into daily Linux workflows using piping. Here are a few examples:
To summarize the contents of a file:
cat myfile.txt | shellm "Summarize this text"
Generate a human-readable summary of files in a directory:
ls -l | shellm "Explain what these files are."
To translate system logs to another language:
journalctl -xe | shellm -t "Translate this to Spanish."
Shellm supports user-defined tools specified in JSON files. This allows Shellm to perform operations beyond simple language model predictions, such as executing shell commands or interacting with APIs. This functionality is highly experimental and new tools will be added as soon as the underlying tool pipeline is more robust.
Tools are read from the config.yaml
file which is searched in the following directories (priority order):
$XDG_CONFIG_HOME/shellm/config.yaml
~/.config/shellm/config.yaml
~/config.yaml
$(dirname "$0")/config.yaml
(same directory as the script)Here’s a sample tool configuration within config.yaml
:
execute_shell_command:
type: function
function:
name: execute_shell_command
description: >-
Executes the specified shell command. Bash syntax allowed. The command string must be complete with all arguments, parameters, redirections and pipes. Multi-line commands are allowed.
parameters:
type: object
properties:
command:
type: string
description: >-
The shell command with all arguments. Warning: It is passed into eval as-is.
raw: true
required:
- command
exec: '{{command}}'
generate:
type: function
function:
name: generate
description: Display LLM-generated output to the user.
parameters:
type: object
properties:
prompt:
type: string
description: >-
The prompt to be passed to the completion endpoint. Supports both
Chat-like instructions and generic prediction/completion.
json:
type: boolean
description: >-
Set to true to format the output as JSON. Works only if JSON is also
used in the prompt
required:
- prompt
# language=sh
exec: |
generate_response "{{prompt}}" 200
When tools are enabled (-t
flag), Shellm can chain tool calls. Example:
shellm -t "Get the current date and time and tell me if it's a weekend."
Shellm's tool execution works in multiple steps:
say
tool call.Variable | Description | Default |
---|---|---|
API_URL |
URL of the Ollama API | http://localhost:11434/api |
MODEL_SMALL |
Default model to use | qwen2.5:3b-instruct-q5_K_M |
VERBOSE |
Enable verbose output | 0 |
USE_TOOL |
Enable tool usage mode | 0 |
For verbose output, use the -v
flag and specify the desired log level:
-v 0
- Errors only-v 1
- Add warnings-v 2
- Add logs specific to tool use-v 3
- Add debug outputshellm -v 3 "Debug the script behavior."
Apart from banking on the significant overlap between "shell" and "llm", the name "Shellm" is also extremely close in spelling and pronunciation to the German word "Schelm", which means "rogue", or "jokester". This adds charm and character to the tool, so bear this in mind when it fails spectacularly.
Contributions are welcome! Feel free to open issues or submit pull requests for bug fixes or new features.
Shellm is released under the GPL License. See the LICENSE file for more details.
Enjoy using Shellm to bring AI capabilities directly into your shell! 😊