0

This is an extension to:
https://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command.

I am looking for a way (through bash and/or readline) to bind a key to a shell function, which modifies the current command line. Possibly through the $BASH_COMMAND variable.

For example, if this is the current command line ($ is the prompt and | is my cursor)

Type:

$ command_foo arg_foo foo|

Then have my shell function replace all of my foo's by bar's, after I press the key that the function is bound to.

I would then expect the command line to read (I don't really care where the new cursor position will be)

$ command_bar arg_bar bar

Of course I can fine tune my function so that only the last foo is replaced by bar, but that's details.

Is there anyway to achieve this via bash and/or readline, possibly utilizing the $BASH_COMMAND shell variable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.