Problem: No way to review or replay previously executed commands.
Solution: Track command execution history with query interface.
sh do
ls("-la")
pwd
cat("file.txt")
end
# Query history
RubyShell.history.last # Most recent command
RubyShell.history.last(5) # Last 5 commands
RubyShell.history.all # All commands in session
# History entry details
entry = RubyShell.history.last
entry.command # "cat file.txt"
entry.stdout # "file contents..."
entry.stderr # ""
entry.exit_code # 0
entry.duration # 0.005
entry.timestamp # 2024-01-15 10:30:45
entry.success? # true
# Search history
RubyShell.history.find_by(command: /git/)
RubyShell.history.find_by(exit_code: 1)
RubyShell.history.successful
RubyShell.history.failed
# Replay command
RubyShell.history.last.replay
# Persist to file
RubyShell.history.save("commands.log")
RubyShell.history.load("commands.log")
# Clear history
RubyShell.history.clear
Problem: No way to review or replay previously executed commands.
Solution: Track command execution history with query interface.