Is there any way to save a keyboard macro in bash?

Solution 1:

Turns out it's really not possible, that is, it wasn't possible until tonight!

Since I was curious to dig into the bash source code anyways I went ahead and added this feature :). We'll see if the bash maintainers apply my patch.

Solution 2:

Best I could think of is to try:

echo >>.inputrc '<ctrl-x e>'

Or if the macro has multiple lines try:

echo >>.inputrc <<EOF
<ctrl-x e>
EOF

If you have used control characters you may wish to put a sed in there to replace them with the right escape codes for inputrc.

Then go in and edit the last line to have the right prefix and suffix for what you are trying to achieve ...