CXD
Command Executor per Directory (cxd) provides a simple interface to save and execute
commands within specific directories.
Background
While working in large codebases with several executables, it was common for me to add
custom scripts and Makefiles to each directory. This allowed me to not have to rely on
bash history to remember my specific commands. However, after one too many git-merge
events overwriting my temporary Makefiles, I wrote cxd.
Dependencies
libsqlite3
Installation
Bash Completions
Clone the files under pkg/completions/bash/ to the first of the following directories.
/usr/share/bash-completion/completions/- (deprecated)
/etc/bash_completion.d/
Zsh Completions
Clone the files under pkg/completions/zsh/ to any directory listed by echo $fpath.
For example, on Debian 12 this includes /usr/share/zsh/vendor-completions by default.
You may need to logout and login for these changes to take effect.
Use
cxd uses a sqlite database to save commands and their respective directories to execute
at a later time. Database cache files can be saved and reused across devices. However,
note that you should NEVER trust a cache file from an outside source, as cxd
will execute arbitrary commands from the database.
Selecting Cache File
By default, cxd will attempt to store the cache file in the following locations, and
fail if unable to construct any.
- Contents of
-f FILEor--file FILE $CXD_CACHE_DIR/cxd.cache$XDG_CACHE_HOME/cxd.cache$HOME/.cache/cxd.cache
Adding a Command
To add a command to the database, use cxd --add <NAME> <CMD> [ARG]....
This will register a command named hello that prints out a greeting.
If you'd like the command to swap directories back to your current $CWD before invoking
the command, pass the --cwd flag.
Similarly, you can set a specific working directory with --dir <DIR>.
If specific environment variables must be set, use --env <KEY>=<VALUE>.
Executing a command
To execute a command from the database, use cxd <CMD>.
Removing a command
To remove a command from the database, use cxd --remove <CMD>.
Listing
To list all commands in the database, use cxd --list.
Clearing
To clear all commands in the database, use cxd --clear.
Tips
Using multiple cache files
It can be useful to segment cache files for specific commands. A simple and ergonomic way to do this is to set aliases.
For example, imagine you want two separate cache files, one for playing media and one for building executables.
Then you can add the following to your .bashrc, .zshrc, or equivalent.
This allows you to run cxd with each cache file as if it were two different commands, build and play.