Home > cq

cq

Cq is a project mainly written in PERL and SHELL, based on the View license.

Command queueing daemon

=pod

=head1 NAME

cq - command queue

=head1 SYNOPSIS

B [B<-d> F

] I [I]

=head1 DESCRIPTION

cq is a simple command-queueing daemon and frontend. It runs a series of commands (jobs) in order in the background. It allows safe interactive editing and viewing of the job queue and editing of jobs without unnecessarily interrupting job execution.

=head2 Overview

cq is split into two parts: the B script, documented here, and B, the command queue daemon. The user never has to deal with cqd directly; the cq fronted handles all interaction.

cq operates within an B. An instance is identified by its instance directory, usually referred to as I, where its state is kept. There can be at most one copy of cqd running per instance.

When running, cqd executes a series of B. Each job is an executable file, usually a shell script, provided by the user. Jobs are placed on a B and executed in FIFO order. cqd takes a job off the top of the queue, makes it the B job, executes it, destroys it, and repeats. If the queue is empty, cqd waits until a new job appears.

The queue may be edited on-the-fly by the user. While the queue is being edited, cqd will not remove jobs from it; it will wait until the user is done editing, then remove and run the next job. Similarly, jobs still on the queue may be edited by the user. If a job that would be made current is being edited, cqd will wait until the user finishes before running it.

cqd can run jobs using a user-specified wrapper program. For example, the author likes to run each job in a screen(1) instance.

=head1 OPTIONS

=over

=item B<-d> F

Use F

as the instance directory. Defaults to the value of the environment variable I.

=back

=head1 CQ COMMANDS

=over

=item B [B<-c> F] [F

]

Makes F

an instance directory (if it already is, it remains so). F defaults to I; if neither is specified, a temporary directory is used. If specified, F is used as a configuration file (see L, below). Outputs sh(1) commands to set the I environment variable, so that future cq invocations will use this cq instance; intended to be used with eval(1), as in C<eval $(cq create)>.

=item B [F]

Destroys the cq instance in F.

=item B

Starts the cq daemon, cqd, which runs jobs in the job queue.

=item B [B<-f>]

Stops the cq daemon, and hence stops the execution of jobs from the queue. If there is a job running, the daemon will complete it before exiting. To stop immediately, terminating the current job, pass the B<-f> flag.

=item B

Cancels a previous B, preventing the cq daemon from stopping when the current job is finished.

=item B B[B

] [B<-e>] [B<-n> I] [I [I]...]

Adds a new job to the end of the queue. The job is named I, which defaults to the least unused natural number. The job will by default be a shell script which runs C. If the B<-e> flag is supplied, the user is given a chance to edit the job before it is enqueued.

=item B B[B] I

Removes I from the job queue.

=item B B[B] I

Opens the job specified by I for editing.

=item B

=item B

Opens the job queue for editing.

=item B B[B]

Shows the current value of I, whether cqd is running and its pid if it is, and the current job if it exists.

=item B B[B]

Lists the jobs in the queue (and those not in the queue if such exist, though they really shouldn't, except during atomic queue modifications).

=item B

Explicitly tell cqd to reload its configuration file. (Unnecessary under normal circumstances.)

=item B

Explicitly tell cqd to rescan the queue. (Unnecessary under normal circumstances.)

=back

=head1 CONFIGURATION

cq has a simple rcfile-like configuration mechanism. An instance's config file is found at I/config; B<cq create -c> merely symlinks this to the specified file, and tells cqd (if it is running) to reload its configuration.

Config files are line-oriented: the first word of a line specifies the configuration variable to set, and the remainder specifies its value. Unix-style comments (from '#' until end-of-line) are supported, and empty lines are ignored.

=head2 Configuration variables

=over

=item I

What command to use to run jobs. Parsed shell-style into a list of words, but not actually passed to sh(1). If any of the words is precisely '%s' (sans quotes), it is replaced with the full path to the job's run-file.

Warning: The precise handling of '%s' and other printf(3)-style escapes, as well as how this command is parsed (whether it is passed to sh(1), whether tilde-expansion or environment variable references are performed), may change in the future.

=back

=head1 SIGNALS

cq uses unix signals to communicate with cqd. For reference, cqd understands the following signals:

=over

=item B

The queue may have changed.

=item B

Stop running after finishing the current job.

=item B

Reload the configuration file.

=back

=head1 ENVIRONMENT VARIABLES

=over

=item I

The default instance directory. This is where cq stores job files, the job queue, lock files, and the other state it maintains.

=item I

The user's editor, invoked when editing of a job or of the job queue etc. is requested.

=back

=head1 BUGS

At the moment, cq is B incomplete. It also has some overly-specific requirements (in particular the Z shell, zsh(1)). Feel free to send patches. I make no promises regarding when these bugs will be fixed or with regards to timeliness of response to patch submissions.

=head1 AUTHOR

Michael Arntzenius [email protected]

=cut