diff options
| -rw-r--r-- | Idea.txt | 4 | ||||
| -rw-r--r-- | incdec | 21 | 
2 files changed, 25 insertions, 0 deletions
| diff --git a/Idea.txt b/Idea.txt new file mode 100644 index 0000000..5a47f60 --- /dev/null +++ b/Idea.txt @@ -0,0 +1,4 @@ +Readline bindings to increment and decrement a number on the command line, like Vim's <C-a> and <C-x>. + +2021.01.03: +Try C-c and replace the number in a new shell line @@ -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+' | 
