Running Jobs

Watching a Command

$ watch -n 5 date
Every 5.0s: date              cherne: Mon Apr 22 16:11:48 2024

Mon Apr 22 16:11:53 EDT 2024
$ watch -t -n 5 date
Mon Apr 22 16:11:53 EDT 2024

Watching Files

$ fswatch -l 1 -x Created -x Removed /tmp

# touch /tmp/a.txt
/private/tmp/a.txt Created IsFile

# rm /tmp/a.txt
/private/tmp/a.txt Created IsFile Removed

And Then There's cron

Git Hooks

# Make a place for this example.
$ mkdir example
$ cd example

# Turn it into a Git repository.
$ git init .
Initialized empty Git repository in /Users/tut/example/.git/

# Create a pre-commit script that always fails (i.e., exits with non-zero status).
$ cat > .git/hooks/pre-commit.sh
#!/bin/sh
echo "hook running"
exit 1

# Make that script executable.
$ chmod 755 .git/hooks/pre-commit.sh

# Run it and check its exit status.
$ .git/hooks/pre-commit.sh
hook running

$ echo $?
1

# Create some content.
$ cat > a.txt
content

# Try committing it.
# The hook should print "hook running" and the commit should be prevented.
$ git add a.txt

$ git commit -m "should not work"
hook running

$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   a.txt
$ cat > .git/hooks/pre-commit
ruff check
exit $?

$ cat > a.py
x = not_defined

$ git add .
$ git commit
a.py:1:5: F821 Undefined name `not_defined`
Found 1 error.

$ cat > a.py
x = 0

$ git add .
$ git commit -m "this commit works"
All checks passed!
[main 7c01aee] this commit works
 1 file changed, 1 insertion(+), 1 deletion(-)

Managing These Examples