You are not logged in.

#1 2016-11-13 14:04:27

ninjaaron
Member
Registered: 2010-12-10
Posts: 296

wlrd: shell loops simplified. (or xargs -I or steriods)

From the github page:

You may think that wrld is some abbreviated form of "world". This is not the case. The world is lame. What isn't lame is iterating on stdin. Probably my favorite thing to do. In the shell, the sanest way to do this is with a while read line; do loop. Forget the world. wrld is the future of iteration.

Raise your hand if you have ever written this loop:

find -name '*foo.bar' -type f|while read line; do
  mv "$line" "$(echo "$line"|sed 's/pat/rep/')"
done

Or the related loop:

for i in *foo.bar; do
  cp ... # I'm too lazy even to finish this example.
done

With wrld, you can write like this:

find -name '*foo.bar' -type f | wrld mv {} '@sed "s/pat/rep/"'

You can do something similar with globs as well:

wrld mv {} '@sed "s/pat/rep/"' -f *foo.bar

This is manifestly better for one-liners in the shell.

`wrld` has many builtin goodies as well. Notably, builtin python regex substitions and expression evaluation as filters for file names. It also has some builtin commands so it doesn't have to spawn a new process each time for common tasks like moving, copying, linking and deleting files (and making directories). More info on the project page.

Check out the github page for more info and install from AUR, with pip3 or directly from github.

Last edited by ninjaaron (2016-11-13 14:12:16)

Offline

#2 2016-11-13 14:08:49

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: wlrd: shell loops simplified. (or xargs -I or steriods)

So... yet another Parallel ? (actually, yapl has a certain ring to it, but apparently reserved to some Haskell clone)

Last edited by Alad (2016-11-13 14:11:40)


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#3 2016-11-13 14:19:59

ninjaaron
Member
Registered: 2010-12-10
Posts: 296

Re: wlrd: shell loops simplified. (or xargs -I or steriods)

yeah, something like that, but mo' betta... or so I keep telling myself.

Last edited by ninjaaron (2016-11-13 14:20:32)

Offline

#4 2016-11-13 15:03:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: wlrd: shell loops simplified. (or xargs -I or steriods)

While loops like that - especially the second one, are a bit odd anyways.  Find has an -exec flag:

find -name '*foo.bar' -type f -exec sh -c 'mv {} $(sed "s/pat/rep/" <<< {})' \;

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2016-11-13 17:38:50

ninjaaron
Member
Registered: 2010-12-10
Posts: 296

Re: wlrd: shell loops simplified. (or xargs -I or steriods)

Trilby wrote:

While loops like that - especially the second one, are a bit odd anyways.  Find has an -exec flag:

find -name '*foo.bar' -type f -exec sh -c 'mv {} $(sed "s/pat/rep/" <<< {})' \;

Yeah. This is about like that, except without having to bother with all the syntax for subshells within subshells.

Offline

Board footer

Powered by FluxBB