cdr

From ProgClub
Revision as of 22:31, 4 December 2014 by John (talk | contribs) (→‎Technical specification: Adding note about test script...)
Jump to: navigation, search

'cdr' is short for 'cd regex'. cdr is the ProgClub regular expression directory changing software. That's the software that allows you to change directory from your terminal by specifying a regular expression for the directory(s) you want to go to. For other projects see projects.

Status

Version 0.1 released!

Motivation

Why this software? Good question!

I have a backup script which creates directories for each computer in /var/backup/sub, for example:

  • /var/backup/sub/amanda/
  • /var/backup/sub/charity/
  • /var/backup/sub/condor/

And so on. Within each computer directory are a number of other directories with the date of the backup, for example:

  • /var/backup/sub/amanda/2014-12-01/
  • /var/backup/sub/amanda/2014-12-02/
  • /var/backup/sub/charity/2014-11-06/
  • /var/backup/sub/charity/2014-11-07/
  • /var/backup/sub/condor/2014-11-26/
  • /var/backup/sub/condor/2014-11-27/

And so on. I wanted to get a list like the above from the command line. So I created this cdr utility. The above list was generated with this cdr command:

$ cdl '/var/backup$/sub/.*/[\\d\\-]+'

Administration

Contributors

Members who have contributed to this project. Newest on top.

All contributors have agreed to the terms of the Contributor License Agreement. This excludes any upstream contributors who tend to have different administrative frameworks.

Copyright

Copyright 2014, Contributors.

License

Licensed under the GPL.

Resources

Downloads

There are no downloads for this project.

Source code

The repository can be browsed online:

https://www.progclub.org/pcrepo/cdr/branches

The latest stable released versions of the code are available from:

https://www.progclub.org/svn/pcrepo/cdr/tags/latest

Or if you want the latest versions for development purposes:

https://www.progclub.org/svn/pcrepo/cdr/branches

Links

Specifications

Functional specification

The functional specification describes what the project does.

The software provides the following set of commands:

cdr

The cdr command is the work horse command. It takes two arguments:

  1. the cdr command
  2. the path regular expression

The command can be one of:

  • next: iterate through all matches
  • list: list all matches
  • xarg: list all matches delimited by a null byte, appropriate for passing to xargs -0
  • count: list the number of matches

Usually the cdr command is invoked by one of the shorter commands that follow:

cdn

The cdn command stands for 'cdr next'. It will iteratively move you through all matching directories. In bash you type:

cdn '/path/to/match'

and you will be cd'ed to the first match. Type the command again (or press the up arrow) and you will be cd'ed to the next match. And so on.

cdl

The cdl command stands for 'cdr list'. It will list all matching directories.

cdx

The cdx command stands for 'cdr xarg'. It will list all matching directories delimited by a null byte. This output is suitable for input into xargs -0.

cdc

The cdc command stands for 'cdr count'. It prints out the number of matching directories.

Technical specification

The technical specification describes how the project works.

The software is comprised of a PHP shell script and some BASH aliases and functions.

The PHP shell script is bin/cdr.php. The BASH aliases/functions are in etc/bash_aliases.sh.

See dev/test.sh for test cases.

Notes

Notes for implementers

If you are interested in using this software here's what you need to know:

Make sure you have PHP5 CLI installed. On Debian/Ubuntu that's:

apt-get install php5-cli

Then check out the latest versions from Subversion, e.g.:

cd /srv
svn co https://www.progclub.org/svn/pcrepo/cdr/tags/latest cdr

Make sure the cdr.php script is executable:

chmod +x /srv/cdr/0.1/bin/cdr.php

Create a symlink for the 'cdr' command in /usr/local/bin:

ln -s /srv/cdr/0.1/bin/cdr.php /usr/local/bin/cdr

Edit your ~/.bash_aliases file and source the functions/aliases:

. /srv/cdr/0.1/etc/bash_aliases.sh

Then open a new terminal and see that things seem to be working with a command such as:

cdl '/.*'

That command should list all the directories in / (root).

Notes for developers

If you're looking to set up a development environment for this project here's what you need to know:

See source code for notes on where to get a development branch.

If you're forking this software add your fork version to the CDR_VERSION constant in bin/cdr.php, e.g.:

const CDR_VERSION='0.1.3-[your fork version]';

Tasks

TODO

Things to do, in rough order of priority:

N/A.

Done

Stuff that's done. Latest stuff on top.

  • JE 2014-12-04: released first version
  • JE 2014-12-04: created project in svn
  • JE 2014-12-04: created project page