Created
October 29, 2025 20:38
-
-
Save balanza/3729dbc50bb989f4b8ab0e82bbcce78b to your computer and use it in GitHub Desktop.
shell: replay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Replay N commands from history, in sequence | |
| # Usage: | |
| # replay <start command index> <number of commands to replay> | |
| replay() { | |
| local A="$1" | |
| local N="$2" | |
| local end=$((A + N)) | |
| # get current shell | |
| local shell="${SHELL:-/bin/sh}" | |
| # history output: skip first field (the number), preserve spaces | |
| history | awk -v start="$A" -v end="$end" '$1 >= start && $1 <= end { $1=""; print substr($0,2) }' | while read -r cmd; do | |
| echo "Running: $cmd" | |
| "$shell" -i -c "$cmd" | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment