aboutsummaryrefslogtreecommitdiffstats
path: root/incdec
diff options
context:
space:
mode:
authorTeddy Wing2021-08-08 15:08:04 +0200
committerTeddy Wing2021-08-08 15:08:04 +0200
commit9338c2cff6b4055f18c19b72a523a1e51d3359af (patch)
tree0db9cc7fcb7df79c0f7bce866cb18927be52b32b /incdec
parent44b8cbfb87afb35ad518186d7cce47fec8a5370b (diff)
downloadreadline-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
Diffstat (limited to 'incdec')
-rw-r--r--incdec14
1 files changed, 11 insertions, 3 deletions
diff --git a/incdec b/incdec
index cad4101..854717d 100644
--- a/incdec
+++ b/incdec
@@ -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+'