Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

capn
====

capn is a package that provides hooks when the current-working-directory changes.

### Installation

$ sudo pip install capn
$ touch ~/.capnhooks

### Configuration

capn uses a simple YAML file for specifying paths and their hooks. As a quick example, consider the following:


settings:
default_type: path
external_hooks:
- ~/.otherhooks
hooks:
- path: /home
type: tree
enter:
- echo entering /home
exit:
- echo exiting /home
- echo /home waves goodbye

- path: ~/
enter:
- echo entering ~/
exit:
- echo exiting ~/

The above establish enter and exit hooks for the two listed directories. As you change directories you should see output indicating each hook's execution. You'll notice that the */home* path has a **type** key with the value **tree**. There are two types of hooks; **path**, which is the default, only triggers for that absolute path. **tree** hooks will trigger when you enter or leave the tree below the specified path. Moving between child-paths below the tree does _not_ trigger the hooks. For example, moving from */ -> /home* would trigger the *enter* hook. Moving from */home -> ~/* would not trigger the exit hook.

Generally the commands specified in the hooks will be the names of shell scripts not single shell commands.

The first section of the configuration currently has two available settings:

* **default_type**: either **path** or **tree**. If setting is not specified, **path** will be used.
* **external_hooks**: a list of paths to other YAML files containing additional hooks. Such files should resemble the **'hooks'** section of the above example configuration.

### Usage

After installing capn you will need to source:

$ source capn

If you no longer wish to have the hooks activated:

$ unhook

### API

add_external_hook(filename, path, hooktype=DEFAULT_TYPE,
enter=[], exit=[]):


Currently capn has a minimal API with a single function that is used to manage programmatically generated external hook files. See the example below:

>>>from capn.config import add_external_hook
>>>filename = "~/.otherhooks"
>>>path = ~/projects/foo/bar
>>>hooktype = 'tree'
>>>enter = ['source ~/projects/foo/bar/bin/activate']
>>>exit = ['deactivate']
>>>add_external_hook(filename, path, hooktype=hooktype,
... enter=enter, exit=exit)
>>>

The above will add a hook to auto de/activate the python-virtualenv whenever the shell is inside the project directory to the file *"~/.otherhooks"*. You will then need to add the filename to the **external_hooks** list in the *"~/.capnhooks"* configuration file.

Metadata

Release files for capn 1.0rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for capn 1.0rc1
File Size Uploaded
capn-1.0rc1.tar.gz 4.3 kB Details

Release files / capn-1.0rc1.tar.gz

Download URL capn-1.0rc1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cdd14995a851d49f9b0975adb6c3136091a0566bf69e110afd8e9412a959d691
BLAKE2b-256 checksum
How to use checksums
a44dbf7b99f0b34ba691ac170538c42ce9a77aa218cd13fdc73db7072eea37a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0rc1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page