{ "info": { "author": "Aaron Christianson", "author_email": "ninjaaron@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "wrld: Avoid writing loops in shell one-liners\n---------------------------------------------\n\nYou may think that ``wrld`` is some abbreviated form of \"world\". This is\nnot the case. The world is lame. What isn't lame is iterating on ``stdin``.\nProbably my favorite thing to do. In the shell, the sanest way to do\nthis is with a ``while read line; do`` loop. Forget the world. ``wrld``\nis the future of iteration.\n\nRaise your hand if you have ever written this loop:\n\n.. code:: bash\n\n find -name '*foo.bar' -type f|while read line; do\n mv \"$line\" \"$(echo \"$line\"|sed 's/pat/rep/')\"\n done\n\nOr the related loop:\n\n.. code:: bash\n\n for i in *foo.bar; do\n cp ... # I'm too lazy even to finish this example.\n done\n\nNote:\n if you have ever written a loop that starts with the words ``for i in\n $(ls ...``, you're doing it wrong. Do one of the above instead. (also,\n the ``while read line; do`` version can also fail if there are\n filenames with newlines, which you might have if you're iterating on\n filenames generated by an idiot.)\n\nWith ``wrld``, you can write like this: ``find -name '*foo.bar' -type f\n| wrld mv {} '@sed \"s/pat/rep/\"'``. You can do something similar with\nglobs as well: ``wrld mv {} '@sed \"s/pat/rep/\"' -f *foo.bar`` This is\nmanifestly better for one-liners in the shell.\n\nYou could also think of it as ``xargs -I{}`` or the ``-exec`` flag from\n``find`` on steroids, because it iterates on stdin, but it also allows\ninlining arbitrary shell commands.\n\n.. code:: bash\n\n $ ls|wrld mv {} '@awk \"{print $2, $1}\"'\n mv 'Arnold Palmer' 'Palmer Arnold'\n mv 'Jane Doe' 'Doe Jane'\n mv 'John Doe' 'Doe John'\n mv 'John Wayne' 'Wayne John'\n mv 'Lucy Lawless' 'Lawless Lucy'\n mv 'Ricki Lake' 'Lake Ricki'\n\nAs you can see, inlined commands have the current line piped to their\nstdin. If you want to use some poorly-designed command that doesn't read\nfrom stdin as the filter, you can also substitute ``{}`` for the current\nline. Use ``\\{}`` if you need a literal '{}'. However, if you can't do\nit with sed or awk, there's always ``perl -pe``, and if you can't do it\nwith ``perl -pe``, I don't want to know about it. You can also see that\n``wrld`` echos back the commands it constructs. You can shut it up with\n``-q``/``--no-echo``. You can also do a \"test run\" to see what the\ngenerated commands will be without actually running them, using\n``-t``/``--test`` flags.\n\nBecause POSIX stupidly allows newlines in file names, this is\nactually a \"dangerous\" example unless can guarantee there are no idiot\nnewlines in the file names. For this reason, you may instead specify a\nlist of file names to iterate over (like, preferably with a glob) with\nthe -f/--file-list flag:\n\n.. code:: bash\n\n $ wrld mv {} '@awk \"{print $2, $1}\"' -f *\n mv 'Doe Jane' 'Jane Doe'\n mv 'Doe John' 'John Doe'\n mv 'Lake Ricki' 'Ricki Lake'\n mv 'Lawless Lucy' 'Lucy Lawless'\n mv 'Palmer Arnold' 'Arnold Palmer'\n mv 'Wayne John' 'John Wayne'\n\nIf you're using a proper shell like fish or zsh, you can do recursive\nglobbing and get quite a lot done this way.\n\n One day, in the far distant future, wrld may support splitting stdin\n on the null byte for compatibility with ``find -print0``. It is a\n little know fact that any task which a computer is capable of\n preforming may be prefomed with the ``find`` command, so compatibility\n is key.\n\nflags\n~~~~~\nwrld is stupid about flags with the command it wraps. However, courtesy\nof ``argparse``, you can tell wrld that no further flags are coming with\nthe ``--`` argument.\n\n.. code:: bash\n\n $ find -type d | wrld -- mv -v {} /some/dir\n ...\n\noptimize\n~~~~~~~~\n\nNote:\n I/O bound tasks will not benefit much from these optimizations.\n\nAs you may note, wrld is capable of spawning a lot of processes. If it's\nsome quick thing, who cares? If your iterating over a million files, it\nmight be bad. wrld offers some internal goodies to speed things along,\nbut they are written in python, so don't expect any miracles! (kind of\nkidding. A few lines of python is way faster than spawning a new\nprocess, but it would be much slower than piping a million lines strait\nthrough ``sed`` or whatever optimized C utility).\n\nThese builtins are for certain common file operations: they have names\nlike \"move\", \"copy\", \"hlink\" and \"slink\".\n\n- ``move`` moves files recursively. It's like ``mv`` without any\n options.\n- ``copy`` copies files recursively. It's like ``cp -R``.\n- ``hlink`` creates hard links. Hard links basically give the same chunk\n of data more than one name on the filesystem. It's called a \"hard\"\n link because of the physiological responce many people experience when\n they realize how powerful this idea can be.\n- ``slink`` creates soft links. These are about like shortcuts on the\n great and glorious Windows operating system. They are called \"soft\"\n links because of what happens to you when you realize the original\n file has moved and all your links are broken. You never have this\n problem with \"hard\" links, but you can't use them across different\n partitions/devices or on directories, so, eh.\n- ``srlink`` expand relative paths to absolute paths when soft linking.\n Like ``ln -sr``.\n- ``remove`` remove stuff. recursively. take care.\n- ``makedir`` makes directories... works like ``mkdir -p``\n\nOther builtins may be added as they occur to me or users ask for them.\n``mv``, ``cp`` and ``ln`` are commands I frequently find myself needing\nin these kinds of loops.\n\nAnother way to optimize is by using ``|`` as a prefix to your filters,\nrather than ``@``; i.e. ``wrld move {} '|awk \"{print $2, $1}\"' -f *``.\nThis opens a single process of ``awk``, filters stdin through that, and\nthen zips the results together with the main loop. This will create\nproblems if the filter produces no output for certain lines of input\n(like ``grep`` would, though I don't know why you'd use grep in a\ncontext like this...), or if you have filenames with newlines, like a\nfreak. So, it will work in most cases. One day I may implement this\nproperly with asyncronous piping, so this won't be a problem.\n\nNote that, until this becomes an asyncronous pipe, this is a speed\nenhancement, but piping in this way consumes additional memory, which\nmay make it infeasable for very large tasks in a low memory environment.\n\nThere are also two buitin filters. ``@py`` allows you to use arbitrary\npython expressions as a filter. The current line or filename is\navailable in the execution context as ``i``.\n\n.. code:: bash\n\n $ wrld move {} '@py i.upper()' -f *\n move 'Arnold Palmer' 'ARNOLD PALMER'\n move 'Jane Doe' 'JANE DOE'\n move 'John Doe' 'JOHN DOE'\n move 'John Wayne' 'JOHN WAYNE'\n move 'Lucy Lawless' 'LUCY LAWLESS'\n move 'Ricki Lake' 'RICKY LAKE'\n\n``@py`` uses a little namespace magic that will import any module you\nhappen to use in your expression on demand. Note that only expressions\nand not statements are supported. ``@py`` combined with ``-f`` should\nalso do the right thing with newlines in file names.\n\nThe other builtin filter is ``s``. The syntax looks a bit like ``sed``,\nbut it's python regex, so refer to the relevant docs if you're not\nalready familiar with it. It's based on Perl, like the regex in most\npopular programming langauges (and unlike sed), but it has a few of its\nown quirks.\n\n.. code:: bash\n\n $ wrld move {} 's/[aeiou]/\u03bb/g' -f *\n move 'Arnold Palmer' 'Arn\u03bbld P\u03bblm\u03bbr'\n move 'Jane Doe' 'J\u03bbn\u03bb D\u03bb\u03bb'\n move 'John Doe' 'J\u03bbhn D\u03bb\u03bb'\n move 'John Wayne' 'J\u03bbhn W\u03bbyn\u03bb'\n move 'Lucy Lawless' 'L\u03bbcy L\u03bbwl\u03bbss'\n move 'Ricki Lake' 'R\u03bbck\u03bb L\u03bbk\u03bb'\n\nIt accepts any flags that can be used in a python regex in the contex of\n``(?[flags])``, so, ``aiLmsux``. In addition, the ``g`` flag is\nsupported, to make it more similar to sed and Perl. While ``/`` is used\nas the delimiter by convention, any non-alphanumeric character may be\nused.\n\nIf the replacement is prefixed with ``\\e``, a python expresison can be\nused, where ``m`` is the re.match object for each match, so that offers\nsome interesting possibilities.\n\nI can neither confirm nor deny that there may be another filter in my\nmind for doing awk-like things based on python's ``str.filter`` method.\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ninjaaron/wrld", "keywords": "evaluate", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "wrld", "package_url": "https://pypi.org/project/wrld/", "platform": "", "project_url": "https://pypi.org/project/wrld/", "project_urls": { "Homepage": "https://github.com/ninjaaron/wrld" }, "release_url": "https://pypi.org/project/wrld/1.1/", "requires_dist": null, "requires_python": "", "summary": "simplified bash loops (or, xargs -I on steroids)", "version": "1.1" }, "last_serial": 3274223, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "ad60950a68abf8de0e0040464e6d616c", "sha256": "f724fe34a8310883c683f5346d04965f4f4cfaf0b668bed0df52b3bcf9815855" }, "downloads": -1, "filename": "wrld-0.1.tar.gz", "has_sig": false, "md5_digest": "ad60950a68abf8de0e0040464e6d616c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8348, "upload_time": "2016-09-27T03:39:54", "url": "https://files.pythonhosted.org/packages/f1/90/27047d92cbc304f29635b6df2cc91e7d9dc5bfb92bbbfa7dfaa3cde556bc/wrld-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "c1842aead31a7321ed887c1cbc655645", "sha256": "eede62388ef37e0aea8f29361008d76087762a9065f544f88409ebae49d3f60a" }, "downloads": -1, "filename": "wrld-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "c1842aead31a7321ed887c1cbc655645", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12935, "upload_time": "2016-10-21T17:18:37", "url": "https://files.pythonhosted.org/packages/63/a5/7def9c20c4c5fde18916eca3074d5012856a449f3aa3dc12312b766cdc38/wrld-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fad11da6a5b7fef195ce11c5fa96a391", "sha256": "bf0ab764c6517a0938113e45176c1f928336cbf9c31b05340a93f300521fed3f" }, "downloads": -1, "filename": "wrld-0.2.tar.gz", "has_sig": false, "md5_digest": "fad11da6a5b7fef195ce11c5fa96a391", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8785, "upload_time": "2016-10-21T17:18:40", "url": "https://files.pythonhosted.org/packages/3b/29/fbf2b21290ca8e894ad385e5779c5170fa308e8ca5c7bda51287e700f099/wrld-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "ca43ec6e718e8ce12f380bd03b6bc92f", "sha256": "27681f063607ae765cbd8216990077543916bd1b8c44c6563618f09cee3ce412" }, "downloads": -1, "filename": "wrld-0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "ca43ec6e718e8ce12f380bd03b6bc92f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13866, "upload_time": "2016-11-06T11:51:37", "url": "https://files.pythonhosted.org/packages/a5/78/00cc1ac3d571a5d977791631da96af25e9dd9daa0a643fd181777cc7f43c/wrld-0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0a2cc7ce7fd2c73180d0ffb87ae9229d", "sha256": "2167cc697910bd1d8ba424c67c1b0252e4c929c9a9f98a3884b09a42ae7a842e" }, "downloads": -1, "filename": "wrld-0.3.tar.gz", "has_sig": false, "md5_digest": "0a2cc7ce7fd2c73180d0ffb87ae9229d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10133, "upload_time": "2016-11-06T11:51:42", "url": "https://files.pythonhosted.org/packages/c3/9d/5111367c007e98d20d1f83726d701e80b6f564a12ac6eb951d5dea4f5249/wrld-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "333d4d0c9ac0086ee6e229ac7f1244a1", "sha256": "229c96b5215b460f94d084d52cb9fd1442c1eda6497e98f71500fdb6bb9e0f6b" }, "downloads": -1, "filename": "wrld-0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "333d4d0c9ac0086ee6e229ac7f1244a1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14039, "upload_time": "2016-11-13T17:23:10", "url": "https://files.pythonhosted.org/packages/c3/90/7435e1e95cec6090a8d469753d893418c22bdaf4174e01ea62552bf87844/wrld-0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0b6a28b2fc0596dc183f8909a556c2e9", "sha256": "1bad587bb8757385c1d88b24a69558781aa996d8c2b4407853d1ca09ce8def7a" }, "downloads": -1, "filename": "wrld-0.4.tar.gz", "has_sig": false, "md5_digest": "0b6a28b2fc0596dc183f8909a556c2e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10253, "upload_time": "2016-11-13T17:23:14", "url": "https://files.pythonhosted.org/packages/20/61/63cac7212a82891552b2cc39039da63951b41a4b0c26bfeee7020e570b7d/wrld-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "95845dfc4fa9d4798f8b317f8dd338fc", "sha256": "f0a8b397c46eea3f35a569133225cdfb7509c8aabde382ded69b21b90c83057d" }, "downloads": -1, "filename": "wrld-0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "95845dfc4fa9d4798f8b317f8dd338fc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14034, "upload_time": "2016-11-13T17:32:48", "url": "https://files.pythonhosted.org/packages/68/0e/10d1185dccd4ee3263af1a23d434d46b449cc5850b96d720d50bb8c1d827/wrld-0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b674b6a979b8aca3441b40318e963689", "sha256": "409919bfcce555e5634bb1b5863a94efdaa19a59cde7c01ae3be5b60b1fb913c" }, "downloads": -1, "filename": "wrld-0.5.tar.gz", "has_sig": false, "md5_digest": "b674b6a979b8aca3441b40318e963689", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10251, "upload_time": "2016-11-13T17:32:52", "url": "https://files.pythonhosted.org/packages/12/bd/35b7380e77ae77ca635a46d65ee616f96f52ecedc2af045db98ab76a1565/wrld-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "6b0790aabecdc93b3da16c0de5e87efa", "sha256": "75a4d51d94c9cf66a3d220e8b472b2ddffe96d4e058fc21a9909222b239bcf91" }, "downloads": -1, "filename": "wrld-0.6-py3-none-any.whl", "has_sig": false, "md5_digest": "6b0790aabecdc93b3da16c0de5e87efa", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14324, "upload_time": "2017-03-26T20:12:36", "url": "https://files.pythonhosted.org/packages/29/c7/9ef17d85105d83e0badb0975ae01ad833a605e970526acb1b425c94dbb51/wrld-0.6-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9f09fbbe4c5b9cbb9822267e76dcc2ce", "sha256": "6c3e6f7eeebf5998566742d02cdd0d5dc0901d7f3b3bb6943e8854fc1e51a546" }, "downloads": -1, "filename": "wrld-0.6.tar.gz", "has_sig": false, "md5_digest": "9f09fbbe4c5b9cbb9822267e76dcc2ce", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10610, "upload_time": "2017-03-26T20:12:39", "url": "https://files.pythonhosted.org/packages/a4/3f/4e3692af943e9e36a6d4f9134c5da6229c7a0416703a7421c9002e01438f/wrld-0.6.tar.gz" } ], "0.7": [ { "comment_text": "", "digests": { "md5": "cd76dc00ec1ad8b9a804b4bd1ebc605d", "sha256": "f2bbf3ebfc35c792ec88ade4d2ccc20cda9c81224d6f0e3a3b97f4ff78db3e1d" }, "downloads": -1, "filename": "wrld-0.7-py3-none-any.whl", "has_sig": false, "md5_digest": "cd76dc00ec1ad8b9a804b4bd1ebc605d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14331, "upload_time": "2017-06-25T18:26:50", "url": "https://files.pythonhosted.org/packages/23/62/04e70e6377e365f813dfcca2138744881306c41d3942ab02756623a845e8/wrld-0.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a3725858eec064edd5e321610e2a7bff", "sha256": "c05cc67233ee1b7ab67769d35e9a26d7b72bb52583b5365925b7939804fbfdb9" }, "downloads": -1, "filename": "wrld-0.7.tar.gz", "has_sig": false, "md5_digest": "a3725858eec064edd5e321610e2a7bff", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11638, "upload_time": "2017-06-25T18:26:55", "url": "https://files.pythonhosted.org/packages/48/a7/355f48846a9fdfc1846efd2e1211c30b0cae5718eeaecb1cf4ab02646f70/wrld-0.7.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "c497d4b1927a19463e952cce89c06ad3", "sha256": "32779e0dcbcb7687f6ba44ce87fcc6984ac952ee1d7393e58d5f32fc4ba2042a" }, "downloads": -1, "filename": "wrld-1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c497d4b1927a19463e952cce89c06ad3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14313, "upload_time": "2017-08-27T09:03:35", "url": "https://files.pythonhosted.org/packages/53/1d/baaeb4766f1717a5600576d24006979c1b40ea129aff5c363fb4d3f53ec4/wrld-1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9ca7e0007d4d0509d75853cadedbac9d", "sha256": "2ae3e806741a025e5f82d783f4707c3031782d1e7db79e75bf1907b398613873" }, "downloads": -1, "filename": "wrld-1.0.tar.gz", "has_sig": false, "md5_digest": "9ca7e0007d4d0509d75853cadedbac9d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11617, "upload_time": "2017-08-27T09:03:38", "url": "https://files.pythonhosted.org/packages/77/8a/c175a78cc6c5a9745df8fa05bd2f5b3ef483ef8f927a549747a18a464803/wrld-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "847facba1f238ddbb54325c9e4f8fa0d", "sha256": "c2eaaf01fd45dd77fa095ce0ed37351c4882a8a699d8a97d5c548f894b594398" }, "downloads": -1, "filename": "wrld-1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "847facba1f238ddbb54325c9e4f8fa0d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14356, "upload_time": "2017-10-24T06:04:25", "url": "https://files.pythonhosted.org/packages/e2/a5/6a922e06d32c003308ce189e8a91b42ac44d00fc24df8149dde8c8e6c224/wrld-1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "01c96b7b0c1b118fa6dd4c575f26c98b", "sha256": "8e0d8ee900f8caea68252cd1b9396107b8c1ca1278102536c35563cbfda8c948" }, "downloads": -1, "filename": "wrld-1.1.tar.gz", "has_sig": false, "md5_digest": "01c96b7b0c1b118fa6dd4c575f26c98b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10983, "upload_time": "2017-10-24T06:04:26", "url": "https://files.pythonhosted.org/packages/66/6b/e2f36117c2d9ec016da43258c88556f382060b1bcab76ecad90fb5cad98e/wrld-1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "847facba1f238ddbb54325c9e4f8fa0d", "sha256": "c2eaaf01fd45dd77fa095ce0ed37351c4882a8a699d8a97d5c548f894b594398" }, "downloads": -1, "filename": "wrld-1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "847facba1f238ddbb54325c9e4f8fa0d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 14356, "upload_time": "2017-10-24T06:04:25", "url": "https://files.pythonhosted.org/packages/e2/a5/6a922e06d32c003308ce189e8a91b42ac44d00fc24df8149dde8c8e6c224/wrld-1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "01c96b7b0c1b118fa6dd4c575f26c98b", "sha256": "8e0d8ee900f8caea68252cd1b9396107b8c1ca1278102536c35563cbfda8c948" }, "downloads": -1, "filename": "wrld-1.1.tar.gz", "has_sig": false, "md5_digest": "01c96b7b0c1b118fa6dd4c575f26c98b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10983, "upload_time": "2017-10-24T06:04:26", "url": "https://files.pythonhosted.org/packages/66/6b/e2f36117c2d9ec016da43258c88556f382060b1bcab76ecad90fb5cad98e/wrld-1.1.tar.gz" } ] }