Running a program automatically on entering and exiting a directory

Running a program automatically on entering and exiting a directory

Post by Zachary Bro » Sun, 15 Jun 1997 04:00:00



I use bash under linux on my 386, with the following function in my
.profile, which looks for .go and .come files on exiting and entering a
directory, and if it finds them, executes them:

cd=()
{
    if [ -O .go ]; then
        source .go;
    fi;
    builtin cd $*;
    if [ -O .come ]; then
        source .come;
    fi

Quote:}

What I would like is for it to *also* search each parent directory all
the way back to the / directory, until it finds a .Go or .Come, and
execute those as well. That way, in addition to having specific
configuration based on directory, it could also be based on whole trees.

I wouldn't ask this question, except that all my own attempts have been
too slow because of my lack of skill. Could someone help me out with an
efficient solution?

Zack

 
 
 

1. automatically running a program on entering and exiting a directory

I use slackware, with the bash shell.

I've found it a great help to have my system automatically configure
itself based on what directory I'm in. The way I do this is as follows:

in my ~/.bashrc file, I have

if test -e /usr/local/bin/cd
then
    alias cd='. /usr/local/bin/cd';
fi

Then, in /usr/local/bin/cd, I have

#!/bin/bash
if test -e .go;
then
    . .go;
fi
"cd" $1
if test -e .come;
then
    . .come;
fi

What all this allows me to do, is to have two files in every directory:
.go and .come. .come is executed whenever I cd into a directory, and .go
is executed when I cd out of the directory. This has a million and one
uses, including having specialty paths and local command configurations
that optimize operations on the data contained in the directory.

The problem is that if the /usr/local/bin/cd command gets deleted after
login, I suddenly lose the ability to change directories until I unalias
cd.

What I am looking for is a more robust way of handling this whole task,
or at least some way to alias the cd command to execute /usr/local/bin/cd
if it exists, and the default cd command if it doesn't.

Any takers?

Zack

2. Display too large

3. How to automatically list the current content directory while enters into a directory

4. Samba + Cyrix Options??

5. running program on entering and leaving directories

6. Successfull recording with GUSMAX???

7. Exiting out of a program normally from a continously running program.

8. Kerberos 5 and Secure RPC

9. does SCO automatically run executables in root directory?

10. Running a program automatically when switching VCs

11. How to run the program automatically?

12. Lilo with RH 7.0 Won't Enter Linux Automatically Anymore

13. How to automatically change mesg to n when I enter MM?