#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2017 Christopher Bratusek		#
#							#
#########################################################

# by joedhon (commandlinefu.com)

case ${1} in

	--help | -h | "")
		bashstyle-help -a "joedhon" -e "" -h "http://www.commandlinefu.com/"\
				-l "Public Domain" -n "quickscript"\
				-s "Create script from last commands in history, starting from last occurrence of ###"\
				-v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
				-o "file:|script filename"
	;;

	* )
		filename="$1"
		history | cut -c 8- | sed -e '/^###/{h;d};H;$!d;x' | \
			sed '$d' > "${filename:?No filename given}"
	;;

esac
