#!/bin/bash session_ts="$(date +%s)" role="$1" shift work() { aichat --save-session --session "$session_ts" --role "$role" "$*" } if [ -n "$1" ]; then work "$@" fi while true; do read -e -r -p "> " input if [ -z "$input" ]; then input="$(rlwrap cat)" fi work "$input" done