1
0
Fork
You've already forked within
0
Run a command in other directories
  • C 81%
  • Roff 11.2%
  • Makefile 7.8%
Find a file
2025年12月17日 17:04:02 +01:00
within.xcodeproj Initial import 2018年11月02日 22:46:21 +01:00
.gitignore 'archive' target 2025年12月17日 17:04:02 +01:00
CHANGELOG.md Release 1.1.4 2021年07月26日 01:44:55 +02:00
LICENSE.md Change license to 2-clause BSD 2021年07月26日 01:39:05 +02:00
Makefile 'archive' target 2025年12月17日 17:04:02 +01:00
README.md Remove sr.ht build definition 2025年12月17日 17:02:11 +01:00
within.1 Use single hyphen as separator 2018年11月12日 13:21:14 +00:00
within.c Change license to 2-clause BSD 2021年07月26日 01:39:05 +02:00

within

Run a command in other directories:

within [-j jobs] directories - command

Description

Runs the given command in all given directories, prepending directory names to output:

$ within msort trickle - make clean
msort: rm -f *.o msort
trickle: rm -f trickle tritty

When a single directory is given the -- may be omitted:

$ within code/msort git status
code/msort: nothing to commit, working tree clean

The -j option specifies how many commands may be run simultaneously. The default is 1.

Implementation

Based around a select() event loop. As many jobs are started as -j allows (1 by default), forking, descending into the given directory and executing the command. For each job, both standard output and standard error are redirected to a pipe that's read by a 'piper' which adds the 'directory:' prefixes to the output. These pipers are effectively coroutines.

The event loop waits for finished jobs, starting new ones if there are directories left, and for data on the pipes.

The select() specific code should be fairly easy to swap out. Point in case, originally kqueue was used.

Running

Should work with any Unix, including Linux and macOS.

Mac users can install from my Homebrew tap

brew install sjmulder/tap/within

To compile, install and uninstal from source:

make
make install [DESTDIR=] [PREFIX=/usr/local] [MANPREFIX=PREFIX/man]
make uninstall [DESTDIR=] [PREFIX=/usr/local] [MANPREFIX=PREFIX/man]

Author

Sijmen J. Mulder (ik@sjmulder.nl)