2

Does bash/readline have a binding or a function that a key combination can be binded to in order to expand in-line braces? Similar to the way M-* key combination can be used for in-line globbing expansion.

So upon performing a key-combination

$ {a..z}

will turn in place into :

$ a b c d e f g h i j k l m n o p q r s t u v w x y z

6
$ $(echo {a..z})

CTRL + ALT + e

$ a b c d e f g h i j k l m n o p q r s t u v w x y z

Note that it will expand all the expansions on the command line. No matter where the cursor is placed.
With this command (and a=this; b=that):

$ echo "$a"; $(echo {a..m}); echo "$b"

This will be expanded:

$ echo this; a b c d e f g h i j k l m ; echo that

From man bash:

shell-expand-line (M-C-e)
Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions. See HISTORY EXPANSION below for a description of history expansion.

  • 1
    Under what circumstances is this supposed to work? I can't reproduce it with bash in Emacs command line editing mode in a tmux session, for example, or on macOS. – Kusalananda Sep 11 '18 at 7:01
  • Make sure that you have the ``` ` ` ``` (or $(...)). Search in man bash for shell-expand-line (M-C-e) @Kusalananda – Isaac Sep 11 '18 at 11:55
  • @Isaac Oh well, maybe the default bash on macOS is too old and the most recent bash on OpenBSD is wrongly configured or something, or something else (in the desktop environment) is highjacking the keystrokes. Because it ain't working. That's why I was interested in the circumstances under which this is supposed to work. – Kusalananda Sep 11 '18 at 12:05
  • @Kusalananda For the keybinding : See what bind -p | grep shell-expand-line gives you. For the brace expansion: did you try doing it with two grave accent characters instead of a dollar-and-parentheses? the latter is a recent update to bash, an enter should expand it too. Tell us your bash --version – elig Sep 23 '18 at 4:27

Your Answer

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

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