diff options
Diffstat (limited to 'incdec.bash')
| -rw-r--r-- | incdec.bash | 37 | 
1 files changed, 29 insertions, 8 deletions
| diff --git a/incdec.bash b/incdec.bash index 029d4ea..7144282 100644 --- a/incdec.bash +++ b/incdec.bash @@ -23,7 +23,7 @@ function __readline_incdec {  	local increment_by="$1"  	local backward="$2" -	line=$(perl -s -e ' +	result="$(perl -s -e '  sub incdec {  	my ($line, $increment_by, $point_position, $is_backward) = @_; @@ -76,28 +76,38 @@ my ($output, $start_position) = incdec(  	$point_position,  	$backward  ); -print $output; +print "$start_position\#$output";  ' \  		-- \  		-line="$READLINE_LINE" \  		-increment_by="$increment_by" \  		-point_position="$READLINE_POINT" \  		-backward="$backward" -	) +	)" -	READLINE_LINE="$line" +	echo "$result"  }  # Increment the nearest number to the left of point by 1.  function __readline_incdec_increment {  	local old_line_length="${#READLINE_LINE}" -	__readline_incdec 1 1 +	result="$(__readline_incdec 1 1)" + +	line="${result#*#}" +	READLINE_LINE="$line"  	local new_line_length="${#READLINE_LINE}" +	local start_position="${result%#*}" +	echo "$start_position .. $READLINE_POINT" +  	# If a negative sign was removed, keep point where it was. -	if [ "$old_line_length" -gt "$new_line_length" ]; then +	if [ \ +		"$old_line_length" -gt "$new_line_length" \ +		-a \ +		"$start_position" -le "$READLINE_POINT" \ +	]; then  		READLINE_POINT="$(($READLINE_POINT - 1))"  	fi  } @@ -106,12 +116,23 @@ function __readline_incdec_increment {  function __readline_incdec_decrement {  	local old_line_length="${#READLINE_LINE}" -	__readline_incdec -1 1 +	result="$(__readline_incdec -1 1)" + +	line="${result#*#}" +	READLINE_LINE="$line"  	local new_line_length="${#READLINE_LINE}" +	local start_position="${result%#*}" +	echo "$start_position .. $READLINE_POINT" + +	# TODO: Point should only move when it's over the number. No, actually when it's >= the start of the number.  	# If a negative sign was added, keep point where it was. -	if [ "$old_line_length" -lt "$new_line_length" ]; then +	if [ \ +		"$old_line_length" -lt "$new_line_length" \ +		-a \ +		"$start_position" -le "$READLINE_POINT" \ +	]; then  		READLINE_POINT="$(($READLINE_POINT + 1))"  	fi  } | 
