diff options
| author | Teddy Wing | 2021-08-08 15:08:04 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-08-08 15:08:04 +0200 | 
| commit | 9338c2cff6b4055f18c19b72a523a1e51d3359af (patch) | |
| tree | 0db9cc7fcb7df79c0f7bce866cb18927be52b32b | |
| parent | 44b8cbfb87afb35ad518186d7cce47fec8a5370b (diff) | |
| download | readline-incdec-9338c2cff6b4055f18c19b72a523a1e51d3359af.tar.bz2 | |
incdec: Increment the number and print the whole line
Thinking I might be able to echo the whole line to the command line
instead of working out how to replace just the number that we've
incremented.
Discovered how to increment a number in a regex substitution from this
Stack Overflow answer by Mark Setchell
(https://stackoverflow.com/users/2836621/mark-setchell):
https://stackoverflow.com/questions/54367360/how-to-increment-the-last-number-in-a-string-bash/54367784#54367784
| -rw-r--r-- | incdec | 14 | 
1 files changed, 11 insertions, 3 deletions
| @@ -14,9 +14,13 @@ function incdec {  	number=${BASH_REMATCH[1]} -	echo "${READLINE_LINE}" -	echo "${BASH_REMATCH[0]}" -	echo "$(($number + 1))" +	# echo "${READLINE_LINE}" +	# echo "${BASH_REMATCH[0]}" +	# echo "$(($number + 1))" + +	incremented_line="$(echo "$line_part" | perl -pe 's/(\d+)/$1+1/e')" + +	printf "${READLINE_LINE:0:$READLINE_POINT}$incremented_line"  }  function __readline_incdec_incdec2 { @@ -24,6 +28,10 @@ function __readline_incdec_incdec2 {  	echo !#  } +# function __readline_incdec_perl { +# 	perl  +# } +  bind -x '"\C-xa+":incdec'  # bind '"\C-xaa":\C-xa+' | 
