Debian Codegraph @

README.rst

raw
1 OnDir
2 =====
3
4 Introduction
5 ------------
6 ondir is a small program to automate tasks specific to certain directories. It
7 works by executing scripts in directories when you enter and leave them.
8
9 Scripts in the doc subdirectory show how to automate this when using either
10 BASH or TCSH.
11
12 Getting Started
13 ---------------
14 1. Add scripts.sh or scripts.tcsh to your startup scripts for BASH or TCSH,
15 respectively.
16 2. Restart your shell.
17 3. Add an entry to your ~/.ondirrc such as those described below.
18 4. Change into the corresponding path.
19 5. Check for success.
20
21 Details
22 -------
23 An example of ondirs usefulness is when editing web pages. I have a umask of 077
24 by default, but when creating web pages in ~/public_html the web content has
25 to be readable by the user the web server runs as. By adding a path section for
26 this directory to my ~/.ondirrc, and corresponding enter and leave sub-sections,
27 any scripts in the enter/leave sub-sections are executed when I enter and leave
28 the directory, respectively. Here is how the entry in my ~/.ondirrc would look::
29
30 enter /home/athomas/public_html
31 umask 022
32
33 leave /home/athomas/public_html
34 umask 077
35
36 And that's all it does. Simple, but effective.
37
38 ondir takes one parameter, the directory you are leaving.
39
40 Note that these scripts will be executed when you pass THROUGH the directory
41 as well. Using the preceding example, typing "cd ~/public_html/mywebpage" will
42 execute the 'enter' in ~/public_html. The reverse is also true: when leaving
43 a path, all 'leave' scripts in the intermediate directories are executed.
44
45 A more useful example
46 ---------------------
47 Ondir is particularly useful with `virtualenv
48 <http://pypi.python.org/pypi/virtualenv>`_. The following config will
49 automatically activate virtualenv's when you change into a directory and
50 deactivate when you move out::
51
52 enter ~/Projects/([^/]+)
53 if [ -r .venv ]; then
54 . ./.venv/bin/activate
55 fi
56
57 leave ~/Projects/([^/]+)
58 deactivate > /dev/null 2>&1