aboutsummaryrefslogtreecommitdiffstats
path: root/incdec
blob: 854717db1fc45f8ac7b51655f9339ba80d5fe2af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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]*([0-9]+)[^0-9]* ]]; then
		return $EX_DATAERR
	fi

	number=${BASH_REMATCH[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 {
	# echo "!!"
	echo !#
}

# function __readline_incdec_perl {
# 	perl 
# }

bind -x '"\C-xa+":incdec'
# bind '"\C-xaa":\C-xa+'

function __readline_incdec_save_readline_point {
	__readline_incdec_readline_point="$READLINE_POINT"
}

bind -x '"\C-xasrp": __readline_incdec_save_readline_point'

# bind '"\C-xaa": \C-xasrp\C-c$(__readline_incdec_incdec2)\e\C-e'
# bind '"\C-xaa": \C-xasrp'
# bind '"\C-xaa": __readline_incdec_incdec2'


# 2021.01.15: Idea: Maybe try using $EDITOR