Crates.io | cxd |
lib.rs | cxd |
version | 0.1.1 |
source | src |
created_at | 2024-08-07 06:08:55.744862 |
updated_at | 2024-09-17 07:27:12.780824 |
description | a command for commands |
homepage | |
repository | https://github.com/wikki01/cxd |
max_upload_size | |
id | 1328122 |
size | 65,692 |
Command Executor per Directory (cxd
) provides a simple interface to save and execute
commands within specific directories.
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
.
libsqlite3
cargo install cxd
Clone the files under pkg/completions/bash/
to the first of the following directories.
/usr/share/bash-completion/completions/
/etc/bash_completion.d/
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.
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.
By default, cxd
will attempt to store the cache file in the following locations, and
fail if unable to construct any.
-f FILE
or --file FILE
$CXD_CACHE_DIR/cxd.cache
$XDG_CACHE_HOME/cxd.cache
$HOME/.cache/cxd.cache
To add a command to the database, use cxd --add <NAME> <CMD> [ARG]...
.
cxd --add hello echo Hi there!
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.
cxd --add --cwd build cargo build
Similarly, you can set a specific working directory with --dir <DIR>
.
cxd --add --dir /src/cxd build cargo build
If specific environment variables must be set, use --env <KEY>=<VALUE>
.
cxd --add --env SOME_ENV=hi hello printenv SOME_ENV
To execute a command from the database, use cxd <CMD>
.
cxd hello
To remove a command from the database, use cxd --remove <CMD>
.
cxd --remove hello
To list all commands in the database, use cxd --list
.
cxd --list
To clear all commands in the database, use cxd --clear
.
cxd --clear
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.
alias build="cxd -f .cache/cxd.build.cache"
alias play="cxd -f .cache/cxd.play.cache"
This allows you to run cxd
with each cache file as if it were two different commands, build
and play
.