'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.
- 1 Status
- 2 Motivation
- 3 Administration
- 4 Resources
- 5 Specifications
- 6 Notes
- 7 Tasks
Version 0.1 released!
Why this software? Good question!
I have a backup script which creates directories for each computer in /var/backup/sub, for example:
And so on. Within each computer directory are a number of other directories with the date of the backup, for example:
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\\-]+'
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 2014, Contributors.
Licensed under the GPL.
There are no downloads for this project.
The repository can be browsed online:
The latest stable released versions of the code are available from:
Or if you want the latest versions for development purposes:
- Read about regular expressions on Wikipedia.
The functional specification describes what the project does.
The software provides the following set of commands:
The cdr command is the work horse command. It takes two arguments:
- the cdr command
- 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:
The cdn command stands for 'cdr next'. It will iteratively move you through all matching directories. In bash you type:
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.
The cdl command stands for 'cdr list'. It will list all matching directories.
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.
The cdc command stands for 'cdr count'. It prints out the number of matching directories.
The technical specification describes how the project works.
The software is comprised of a PHP shell script and some BASH aliases and functions.
See dev/test.sh for test cases.
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:
Then open a new terminal and see that things seem to be working with a command such as:
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]';
Things to do, in rough order of priority:
Stuff that's done. Latest stuff on top.