#!/bin/bash
# 1. Define the number of recent commands to replay (defaults to 5 if no argument is passed)
NUM_COMMANDS=${1:-5}
# 2. Point to the primary history file and explicitly enable history tracking
HISTFILE=~/.bash_history
set -o history
# 3. Read the history file into the current script session
history -r
# 4. Extract the commands, skipping the execution of this script itself
# We use 'tail' to get the last N commands, then loop and run them.
history | tail -n "$((NUM_COMMANDS + 1))" | head -n "$NUM_COMMANDS" | awk '{$1=""; print $0}' | while read -r cmd; do
echo "========================================"
echo "Replaying: $cmd"
echo "========================================"
eval "$cmd"
done
FoldFold allExpandExpand allAre you sure you want to delete this link?Are you sure you want to delete this tag?
The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community