#!/bin/bash set -eu if [ $# -lt 1 ]; then cat << __USAGE__ Usage: $0 Example: $0 "show current working directory" pwd $0 "list up files with file size" ls -l __USAGE__ exit 1 fi INSTRUCTION="$1" # Create Environemnt info SYSTEM_PROFILE="$(system_profiler SPHardwareDataType -json | jq -rMc '.SPHardwareDataType[0] | ["Model: \(.machine_model)","Chip: \(.chip_type)", "Memory: \(.physical_memory)"][]')" OS_INFO="OS: $(sw_vers --productName) $(sw_vers --productVersion)" ENVIRONMENT_INFO="${SYSTEM_PROFILE}\n${OS_INFO}" # Create prompt TMP_PROMPT=/tmp/gemma3command_prompt.txt cat > $TMP_PROMPT << '__INSTRUCTION__' ``` You are shell command generator. Please output appropreate command for the instruction. Do not print extra descriptions. All you print is command text. # Environment {{ENVIRONMENT}} # Examples ## Example1 現在のディレクトリのファイルリストを出力してください ls ## Example2 awkで2行目のみを出力してください awk '{print $2}' # Instruction {{INSTRUCTION}} ``` __INSTRUCTION__ perl -i'' -pe "s|{{ENVIRONMENT}}|${ENVIRONMENT_INFO}|g" $TMP_PROMPT perl -i'' -pe "s|{{INSTRUCTION}}|${INSTRUCTION}|g" $TMP_PROMPT # Execute gpt to generate command RESULT=/tmp/gemma3command_result.txt ollama run gemma3 "$(< $TMP_PROMPT)" | perl -ne 'chomp; print if $_ !~ /^\s*$/' | tee $RESULT cat $RESULT | pbcopy