Skip to content

Commit eeb0b11

Browse files
committed
Tweaks
1 parent ad52e8c commit eeb0b11

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ If you're already familiar with shell scripting and the Unix toolset, here is a
3636
| `cut` | [`Column`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Column) |
3737
| `dirname` | [`Dirname`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Dirname) |
3838
| `echo` | [`Echo`](https://pkg.go.dev/github.com/bitfield/script#Echo) |
39+
| `find` | [`FindFiles`](https://pkg.go.dev/github.com/bitfield/script#FindFiles) |
3940
| `grep` | [`Match`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Match) / [`MatchRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.MatchRegexp) |
4041
| `grep -v` | [`Reject`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Reject) / [`RejectRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.RejectRegexp) |
4142
| `head` | [`First`](https://pkg.go.dev/github.com/bitfield/script#Pipe.First) |
42-
| `find -type f` | [`FindFiles`](https://pkg.go.dev/github.com/bitfield/script#FindFiles) |
4343
| `jq` | [`JQ`](https://pkg.go.dev/github.com/bitfield/script#Pipe.JQ) |
4444
| `ls` | [`ListFiles`](https://pkg.go.dev/github.com/bitfield/script#ListFiles) |
4545
| `sed` | [`Replace`](https://pkg.go.dev/github.com/bitfield/script#Pipe.Replace) / [`ReplaceRegexp`](https://pkg.go.dev/github.com/bitfield/script#Pipe.ReplaceRegexp) |

script.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ func File(path string) *Pipe {
8383
// Each line of the output consists of a slash-separated path, starting with
8484
// the initial directory. For example, if the directory looks like this:
8585
//
86-
// test/
87-
// 1.txt
88-
// 2.txt
86+
// test/
87+
// 1.txt
88+
// 2.txt
8989
//
9090
// the pipe's output will be:
9191
//
92-
// test/1.txt
93-
// test/2.txt
92+
// test/1.txt
93+
// test/2.txt
9494
func FindFiles(path string) *Pipe {
9595
var fileNames []string
9696
walkFn := func(path string, info os.FileInfo, err error) error {
@@ -119,7 +119,7 @@ func Get(URL string) *Pipe {
119119
// be set, and if the file does exist, the pipe will have no error status. This
120120
// can be used to do some operation only if a given file exists:
121121
//
122-
// IfExists("/foo/bar").Exec("/usr/bin/something")
122+
// IfExists("/foo/bar").Exec("/usr/bin/something")
123123
func IfExists(path string) *Pipe {
124124
p := NewPipe()
125125
_, err := os.Stat(path)
@@ -133,7 +133,7 @@ func IfExists(path string) *Pipe {
133133
// path, one per line. path can be a glob expression, as for [filepath.Match].
134134
// For example:
135135
//
136-
// ListFiles("/data/*").Stdout()
136+
// ListFiles("/data/*").Stdout()
137137
//
138138
// ListFiles does not recurse into subdirectories; use [FindFiles] instead.
139139
func ListFiles(path string) *Pipe {
@@ -212,7 +212,7 @@ func (p *Pipe) Basename() *Pipe {
212212
return p.FilterLine(filepath.Base)
213213
}
214214

215-
// Bytes returns the contents of the pipe as a []]byte, or an error.
215+
// Bytes returns the contents of the pipe as a []byte, or an error.
216216
func (p *Pipe) Bytes() ([]byte, error) {
217217
res, err := io.ReadAll(p)
218218
if err != nil {
@@ -247,15 +247,15 @@ func (p *Pipe) Column(col int) *Pipe {
247247
// This makes it convenient to write programs that take a list of paths on the
248248
// command line. For example:
249249
//
250-
// script.Args().Concat().Stdout()
250+
// script.Args().Concat().Stdout()
251251
//
252252
// The list of paths could also come from a file:
253253
//
254-
// script.File("filelist.txt").Concat()
254+
// script.File("filelist.txt").Concat()
255255
//
256256
// Or from the output of a command:
257257
//
258-
// script.Exec("ls /var/app/config/").Concat().Stdout()
258+
// script.Exec("ls /var/app/config/").Concat().Stdout()
259259
//
260260
// Each input file will be closed once it has been fully read. If any of the
261261
// files can't be opened or read, Concat will simply skip these and carry on,
@@ -403,7 +403,7 @@ func (p *Pipe) Exec(cmdLine string) *Pipe {
403403
// This is mostly useful for substituting data into commands using Go template
404404
// syntax. For example:
405405
//
406-
// ListFiles("*").ExecForEach("touch {{.}}").Wait()
406+
// ListFiles("*").ExecForEach("touch {{.}}").Wait()
407407
func (p *Pipe) ExecForEach(cmdLine string) *Pipe {
408408
if p.Error() != nil {
409409
return p
@@ -420,7 +420,7 @@ func (p *Pipe) ExecForEach(cmdLine string) *Pipe {
420420
if err != nil {
421421
return err
422422
}
423-
// strings.Fields doesn't handle quotes
423+
// strings.Fields doesn't handle quotes
424424
args, ok := shell.Split(cmdLine.String())
425425
if !ok {
426426
return fmt.Errorf("unbalanced quotes or backslashes in [%s]", cmdLine.String())
@@ -523,15 +523,15 @@ func (p *Pipe) First(n int) *Pipe {
523523
//
524524
// For example, we could take a common shell pipeline like this:
525525
//
526-
// sort input.txt |uniq -c |sort -rn
526+
// sort input.txt |uniq -c |sort -rn
527527
//
528528
// and replace it with:
529529
//
530-
// File("input.txt").Freq().Stdout()
530+
// File("input.txt").Freq().Stdout()
531531
//
532532
// Or to get only the ten most common lines:
533533
//
534-
// File("input.txt").Freq().First(10).Stdout()
534+
// File("input.txt").Freq().First(10).Stdout()
535535
//
536536
// Like Unix uniq(1), Freq right-justifies its count values in a column for
537537
// readability, padding with spaces if necessary.
@@ -828,9 +828,9 @@ func (p *Pipe) WithError(err error) *Pipe {
828828
// [Pipe.Do], [Pipe.Get], or [Pipe.Post]. For example, to make a request using
829829
// a client with a timeout:
830830
//
831-
// NewPipe().WithHTTPClient(&http.Client{
832-
// Timeout: 10 * time.Second,
833-
// }).Get("https://example.com").Stdout()
831+
// NewPipe().WithHTTPClient(&http.Client{
832+
// Timeout: 10 * time.Second,
833+
// }).Get("https://example.com").Stdout()
834834
func (p *Pipe) WithHTTPClient(c *http.Client) *Pipe {
835835
p.httpClient = c
836836
return p

0 commit comments

Comments
 (0)