Friday, May 22, 2015

When "cd" has no arguments

In a previous post I wrote about commands and channels in Clive. Since then, things have evolved a bit I think it's worth a post.

The cd command, to change the current directory, no longer has a file name argument. Instead, it receives the directory entry to bet set as the new dot from the standard input, like everybody else does to operate on files!. That is:

        /tmp | cd

changes dot to /tmp.

As it can be seen, the first component of the pipe is not a command, but a file name. The Clive shell, Ql, is departing even more from the venerable UNIX sh. Ql commands correspond to streams as explained in the previous post. Since I wrote that post, Ql evolved as well.

Pipe-lines in Ql can be as simple as a set of file names (that is, pairs of a UNIX-like file name and predicate to find files of interest).  One example, list go source files:
       % ,~*.go

(empty name, which defaults to ".", and ~*.go as predicate to locate Go files).

Further commands may be added to pipe-lines to process the directory entries found, like in the first example, or in this one:
        % ,~*.go | pf -l
        --rw-r--r--   2.1k  /zx/sys/src/clive/app/ql/Q/Q.go
        --rw-r--r--   6.3k  /zx/sys/src/clive/app/ql/bltin.go

For those cases when we really want to execute a command that takes no files as input we can just pipe nothing, so Ql does not assumes that the first series of names select files:

        % |date
        Fri May 22 19:31:06 CEST 2015

Doing a recursive grep is now delightful:
        % ,~*go |> gr '"Q"'
        Q/Q.go:27: os.Args[0] = "Q"

This used "|>" instead of "|" to ask Ql to retrieve file data and not just directory entries.

More on Ql soon.