Hi marc! 2019-11-25 21:23 GMT, Marc Chantreux <e...@phear.org>: > hello people, > > some of the things i really enjoy in zsh comes from rc > (setopt rcquotes, the ^ expansion, the alternative syntax > for constrol structures that are close to rc, ...) but > both the codebase and the binary are very large. > > i'm experimenting replacing zsh by rc when the rc > counterpart is good enough. but it seems i reach the > limits of rc very soon. example > > in an mkfile, i can write things like that > > PUBLIC = `{ echo *.md } > PAGES = ${PUBLIC:%.md=pub/%.html} > > in zsh, i can write > > ls *.md > set -- *.md(:r) # (:r) will remove the tailing .md > pages=( pub/$^@.html ) > print -l $pages > > as a result, i get > > l'autre.md > this is.md > pub/l'autre.html > pub/this is.html > > there is nothing like the ':' modifiers or ${p%.md} > alike expansions in rc so i try to figure out what > would be an idiomatic way to do that in rc. > > i tried > > pages=(`{ ls *.md | sed 's/md$/html/; s/md''/html''/' }) > echo pub/^$pages > > which gives me > > pub/l'autre.html pub/this pub/is.html > > close ... but wrong :) i can add klugdes around it but i > feel i missed something. Any advice when it comes to applying > a transformation to a list with rc? > > regards > marc > > >
I forgot, then remembered this old trick from the Rc paper, by Tom Duff [1]: [dank@meme ~]$ rc % cd /tmp % pwd /tmp % mkdir pub % cd pub % touch 'l''autre.md' % touch 'this is.md' % cd .. % mv pub/*md . % pages=`{ls *.md | sed 's/\.md$/.html/g'} % echo pub/^$pages pub/l'autre.html pub/this pub/is.html % printf 'pub/%s ' $pages pub/l'autre.html pub/this pub/is.html % % % printf 'pub/%s ' $"pages pub/l'autre.html this is.html % % echo $pages(1) l'autre.html % echo $pages(2) this % # ah yep, i'm dump % # dumb* % ifs=' ' % pages=`{ls *.md | sed 's/\.md$/.html/g'} % echo pub/^$pages pub/l'autre.html pub/this is.html % Simply set ifs to the newline during the expansion of your files and you're done. [1]: http://doc.cat-v.org/plan_9/4th_edition/papers/rc