Is there something like brace expansion in bash or zsh for eshell?
For those unfamiliar with brace expansion: it is a part of shell expansion in some shells, such as bash or zsh that works as follows: if a word contains a list of words in braces, you get a list of copies of the word with the part in braces replaced by each of the words in the list in turn. This is clearer with an example: the command blah x{a,b,c}y
is transformed to blah xay xby xcy
by shell expansion, before running blah
.
EDIT:
Assuming that @rekado is right and there is no builtin, I wrote this short function that does brace-like expansion:
(defun be (&rest args)
(cond
((null args) '(""))
((null (cdr args))
(let ((hd (car args)))
(cond
((vectorp hd) (cl-mapcan #'be hd))
((listp hd) (apply #'be hd))
((atom hd) (list (format "%s" hd))))))
(t (let ((be-tl (be (cdr args)))
(r '()))
(dolist (x (be (car args)))
(dolist (y be-tl)
(push (concat x y) r)))
(reverse r)))))
It uses lists (or simply passing multiple arguments) for sequencing and vectors to indicate choice. The atoms can be given as strings, symbols or numbers. For example:
bash$ echo a{b,c{d,e}f}{g,h}i
abgi abhi acdfgi acdfhi acefgi acefhi
(be '(a [b (c [d e] f)] [g h] i))
("abgi" "abhi" "acdfgi" "acdfhi" "acefgi" "acefhi")
(be 'a [b (c [d e] f)] [g h] 'i)
("abgi" "abhi" "acdfgi" "acdfhi" "acefgi" "acefhi")