diff options
| author | Teddy Wing | 2021-01-09 16:50:27 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2021-01-09 16:50:27 +0100 | 
| commit | 7250469c78b98a124e844ea6733d188695d2b888 (patch) | |
| tree | 85cab0086756acaf5b4cf99e538d6a347fb54e41 /incdec | |
| download | readline-incdec-7250469c78b98a124e844ea6733d188695d2b888.tar.bz2 | |
Idea for a Readline binding to increment/decrement a number
Want something similar to <C-a> and <C-x> in Vim. This function matches
and increments the number, but I'm currently stymied on how to insert
the number into the current line. There doesn't appear to be a way to do
that, except perhaps with the `shell-expand-line` function, and I don't
want to use that because I just want to insert the number, not expand
other parts of the shell line.
The other sticking point is how to read the value of the
`universal-argument`. There doesn't currently seem to be a way to do
that in a custom function.
I had a new idea for the number insertion problem, though. It's possible
I could replace the number, <C-c> the line, and reinsert a new copy with
the incremented/decremented number on the new shell line. That still
wouldn't resolve the `universal-argument` problem.
Diffstat (limited to 'incdec')
| -rw-r--r-- | incdec | 21 | 
1 files changed, 21 insertions, 0 deletions
| @@ -0,0 +1,21 @@ +function incdec { +	local EX_DATAERR=65 + +	# Portion of the line from point to the end of the line. +	local line_part="${READLINE_LINE:$READLINE_POINT}" + +	# Number to increment. +	local number= + +	# If the line part doesn't contain a number, exit. +	if ! [[ "$line_part" =~ ([0-9]+) ]]; then +		return $EX_DATAERR +	fi + +	number=${BASH_REMATCH[1]} + +	echo "$(($number + 1))" +} + +# bind -x '"\C-xa+":incdec' +# bind '"\C-xaa":\C-xa+' | 
