More often than not, I typed a couple of commands and realized that I will need those more often.
So I redirected my history into a file history > somefile.sh
and edited that, removing line numbers and timestamps.
Tedious work that can be automated with the following shell-function for bash.
qs () {
# Quickly turns a shell-session into a script.
# --------------------------------------------
# The function will
# - delete history number
# - delete history timestamp
# - write all commands after "###" to the end of your history to somefile.sh
#
# Usage:
# - Start your session with "###<enter>".
# - Type your commands.
# - Run qs somefilename.sh.
# - Edit somefile.sh to your liking.
local filename="$1"
history \
| sed 's/^[[:blank:]]\+[0-9]\+[[:blank:]]*//' \
| sed -E 's/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} //' \
| sed '/^###/{h;d};H;$!d;x' \
| sed '$d' \
> ${filename:?No filename given}
}