Subject: Re: rebase [-i --exec | -ix] <CMD>...

From: Johannes Sixt <[email-masked]>
Date: Thu, 07 Jun 2012 22:59:24 +0200

Am 07.06.2012 18:46, schrieb Lucien Kong:
> +# Add commands after a pick or after a squash/fixup serie
> +# in the todo list.
> +add_exec_commands () {
> +	OIFS=$IFS
> +	IFS=$LF
> +	for i in $cmd
> +	do
> +		tmp=$(sed "/^pick .*/i\exec $i" "$1")
> +		echo "$tmp" >"$1"
> +		tmp=$(sed '1d' "$1")
> +		echo "$tmp" >"$1"
> +		echo "exec $i" >>"$1"
> +	done
> +	IFS=$OIFS
> +}

How about this?

	{
		first=t
		while read -r insn rest
		do
			case $insn in
			pick)
				test -n "$first" ||
				printf "%s" "$cmd"
				;;
			esac
			printf "%s %s\n" "$insn" "$rest"
			first=
		done
		printf "%s" "$cmd"
	} <"$1" >"$1.new" &&
	mv "$1.new" "$1"

together with:

> +	-x)
> +		test 2 -le "$#" || usage
> +		cmd="${cmd:+"$cmd$LF"} $2"
> +		shift
> +		;;

		cmd="${cmd}exec $2${LF}"

(I did not test this.)

-- Hannes