Skip to content

Commit 2f47e01

Browse files
committed
Explaining the new 'completions' subcommand in the README.
1 parent aa80795 commit 2f47e01

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Loops in bash are surprisingly complicated and fickle! I wanted a simple and int
5151
- [Create a backup for all files in a directory](#create-a-backup-for-all-files-in-a-directory)
5252
- [Keep trying a failing script until it passes, up to 5 times](#keep-trying-a-failing-script-until-it-passes-up-to-5-times)
5353
- [More examples](#more-examples)
54+
- [Shell completions](#shell-completions)
5455
- [Contributing](#contributing)
5556
- [License](#license)
5657
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -172,7 +173,7 @@ Or until a certain date/time with `--until-time`:
172173
11235
173174
35925
174175
666
175-
$
176+
$
176177

177178
Or until a program succeeds with `--until-success`:
178179

@@ -194,7 +195,7 @@ Or until it matches a regular expression with `--until-match`:
194195

195196
$ loop 'date' --until-match "(\d{4})"
196197
Thu May 17 10:51:03 EDT 2018
197-
$
198+
$
198199

199200
### Iterating Over Lists and Standard Inputs
200201

@@ -204,13 +205,13 @@ Loops can iterate over all sorts of lists with `--for`:
204205
red
205206
green
206207
blue
207-
$
208+
$
208209

209210
And can read from the standard input via pipes:
210211

211212
$ cat /tmp/my-list-of-files-to-create.txt | loop 'touch $ITEM'
212213
$ ls
213-
hello.jpg
214+
hello.jpg
214215
goodbye.jpg
215216

216217
You can also easily pipe lists to `loop`:
@@ -278,20 +279,29 @@ If you've got a whole list of files that you want to create backup copies of, yo
278279

279280
_This is an [example from StackExchange](https://unix.stackexchange.com/questions/82598/how-do-i-write-a-retry-logic-in-script-to-keep-retrying-to-run-it-upto-5-times/)._
280281

281-
> I want to write logic in shell script which will retry it to run again after 15 sec upto 5 times based on "status code=FAIL" if it fails due to some issue.
282+
> I want to write logic in shell script which will retry it to run again after 15 sec upto 5 times based on "status code=FAIL" if it fails due to some issue.
282283
283-
There are so many questions like this on StackExchange, which all end up with long threads of complicated answers.
284+
There are so many questions like this on StackExchange, which all end up with long threads of complicated answers.
284285

285286
With `loop`, it's a simple one liner:
286287

287-
loop './do_thing.sh' --every 15s --until-success --num 5
288+
loop './do_thing.sh' --every 15s --until-success --num 5
288289

289290
Which will do the thing every 15 seconds until it succeeds, for a maximum of five times.
290291

291292
### More examples
292293

293294
Got any more useful examples? Send a pull request!
294295

296+
## Shell completions
297+
298+
To generate shell completions just use the `completions` subcommand and pass the
299+
shell to generate the completion for. For example to generate completions for zsh run:
300+
301+
loop completions zsh
302+
303+
The completion goes to the standard output and you can redirect it to some file.
304+
295305
## Contributing
296306

297307
This project is still young, so there is still plenty to be done. Contributions are more than welcome!

0 commit comments

Comments
 (0)