quickscript 781 Bytes
Newer Older
1 2 3 4 5 6 7
#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
8
# Copyright 2007 - 2015 Christopher Bratusek		#
9 10 11 12 13
#							#
#########################################################

# by joedhon (commandlinefu.com)

14 15 16 17 18
case ${1} in

	--help | -h | "")
		bsng-help -a "joedhon" -e "" -h "http://www.commandlinefu.com/"\
				-l "Public Domain" -n "quickscript"\
19
				-s "Create script from last commands in history, starting from last occurrence of ###"\
20 21 22 23 24 25 26 27 28 29 30
				-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