Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to permanently save a keyboard macro that I've recorded using C-x ( and C-x ). Is there an easy way to "see the source" for my newly recorded macro so that I can bind it to a keyboard shortcut in ~/.inputrc?

I thought dump-macros would do it, but it doesn't seem to...

share|improve this question
    
Well, I'll be damned. I didn't know about this feature. –  Charlie Martin Jun 11 '11 at 0:53
    
I use gnome-terminal and gconf-editor for configuring keyboard shortcuts. –  ilius Jun 11 '11 at 12:39

4 Answers 4

up vote 1 down vote accepted

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.

share|improve this answer

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 ...

share|improve this answer
    
save a step, edit .inputrc, position to wherever you want the macro and C-x e to 'type it in'. But yeah, I'd say this is the best way, of course, you can put it anywhere you want, it's just a bunch of keystrokes. If you're not in the 'right mode/place/program', you'll likely get misunderstood inputs. But one would expect that if you didn't use the macro in the right place, right? –  lornix Sep 18 '11 at 22:08

It appears that .inputrc allows you to just edit your commands in. I tried using dump-macros also but couldn't get it to work nor is there much documentation about it. Perhaps it doesn't work or is deprecated.

If there was a command like xev for emacs bindings, that would be helpful. In any case, I think your best bet is to edit inputrc using the guidelines in the first link below at the bottom of the page. It's quite easy to do.

The second link is an example inputrc file for help figuring out how to set up macros.

As an aside, there is also a cool command called bind -P which will list all of your macros.

http://www.gnu.org/software/bash/manual/html_node/Miscellaneous-Commands.html#Miscellaneous-Commands

Here's an example inputrc file:

http://www.gnu.org/software/bash/manual/html_node/Sample-Init-File.html#Sample-Init-File

share|improve this answer
    
Yeah, the whole point is to not have to write the macro by hand, but instead print out the one I just recorded... –  mgalgs Jun 21 '11 at 4:06
    
turns out dump-macros simply prints out what your currently defined macros would output. –  mgalgs Oct 14 '11 at 8:54

Add this line to .inputrc:

alias macro
share|improve this answer
    
oh, thanks for correcting that, my bad :/ –  FALL3N Jun 26 '11 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.