Ad-hoc dispatcher; a system for creating ad-hoc macros
Create ad-hoc macros to be dispatched within their own namespace.
This readme will give you enough information to get up and running with ahd. If you are confused about terminology used then take a look at the glossary section of the docs. If you are looking for more in-depth documentation:
ahd allows you to take annoying to remember commands and organize them into easy to re-use macros.
sudo ahd register no-pdfs "rm *.pdf" "~/Desktop/*"
.~
is converted to %USERPROFILE%
on windows, \
paths are converted to /
on nix systems and vice-versa./development
on your desktop using the *nix standard ~/Desktop/development/*
works on both *nix and windows.A full roadmap for each project version can be found here: https://github.com/Descent098/ahd/projects
Really the possibilities are only limited to what you can type in your regular terminal, but here are some good examples:
The easiest way to understand why this project is useful is with an example. Let’s say you want to write a simple script to take all the PDF’s in a directory and put them in a .7z
archive and then remove them. Well all you need is this simple command 7za a -t7z PDFs.7z *.pdf && rm *.pdf
…
Yeah, pretty awful to remember. Assuming we want to do this every so often let’s make a script we can call. Currently with bash you need to drop the script in usr/bin
(and try to remember what you called it), or add it to your bash/fish/zsh aliases (assuming you use the alias file, or .bashrc
etc. if you don’t), and on windows it’s just not even worth it.
Enter ahd, you can register a macro (lets call it zip-pdfs) using the same annoying command, in this case sudo ahd register zip-pdfs "7za a -t7z PDFs.7z *.pdf && rm *.pdf" "."
. Now when we want to re-use this macro in the directory we’re in you just type ahd zip-pdfs
.
If you forget the name there’s a list command, and if you use a longer name there’s bash autocomplete (fish and zsh support coming later).
The primary audience is developers looking to speed up annoying workflows. However there are a number of other people it could benefit, such as:
Once you have python3 and pip you have a few installation options.
Run pip install ahd
or sudo pip3 install ahd
(need a network connection)
pip install .
or sudo pip3 install .
in the root directory (one with setup.py)
Usage:
ahd [-h] [-v]
ahd list [-l]
ahd docs [-a] [-o]
ahd config [-e] [-i CONFIG_FILE_PATH]
ahd register <name> [<command>] [<paths>]
ahd <name> [<command>] [<paths>] [-d]
Options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-l, --long Shows all commands in configuration with paths and commands
-a, --api shows the local API docs
-o, --offline shows the local User docs instead of live ones
-e, --export exports the configuration file
-i CONFIG_FILE_PATH, --import CONFIG_FILE_PATH
imports the configuration file
-d, --details prints the details of a command
The register command allows you to register a command to be used later on.
Required Arguments:
\ahd <name>
.
\rm *.pdf
and so you would do ahd register <name> "rm *.pdf" <paths>
.
It is generally advised to use encapsulating quotes since this avoids argument parsing artifacts.
\ahd register <name> <command> "~/Desktop"
.
It is generally advised to use encapsulating quotes since this avoids argument parsing artifacts. Additionally you can specify multiple directories through comma delimiting, for example: ahd register <name> <command> "~/Desktop, ~/Documents, ~/Pictures"
, or you can use path expansion which will match directories through regex or wildcards. For example to run a command in all directories within the desktop you could do ahd register <name> <command> "~/Desktop/*"
or just use regex to match paths more explicitly for example to only include folders on the desktop that are numbers between 0-9 you could do: ahd register <name> <command> "~/Desktop/[0-9]"
.
You can use a registered command by simply typing ahd <name>
, where <name>
is whatever name you gave to the command.
Optional Arguments:
\git pull
over the specified paths. You want to run a different command on the paths (lets say remove all the pdfs in the folder) You can do: ahd <name> "rm *.pdf"
which will execute rm *.pdf
instead of git pull
on the defined paths.
It is generally advised to use encapsulating quotes since this avoids argument parsing artifacts.
\git pull
against ~/Desktop/*
, but now you want to run git pull
against ~/Documents/*
you can use ahd <name> "." "~/Documents/*"
and it will run the macro against ~/Documents/*
instead of ~/Desktop/*
It is generally advised to use encapsulating quotes since this avoids argument parsing artifacts. Additionally you can specify multiple directories through comma delimiting, for example: ahd register <name> <command> "~/Desktop, ~/Documents, ~/Pictures"
, or you can use path expansion which will match directories through regex or wildcards. For example to run a command in all directories within the desktop you could do ahd register <name> <command> "~/Desktop/*"
or just use regex to match paths more explicitly for example to only include folders on the desktop that are numbers between 0-9 you could do: ahd register <name> <command> "~/Desktop/[0-9]"
.
The list command shows a list of your current registered commands.
Optional Arguments:
The docs command is designed to bring up documentation as needed, you can run ahd docs
to open the documentation site in the default browser.
Optional Arguments:
-a or --api: Used to serve local API documentation (Not yet implemented)
-o or --offline: Used to serve local user documentation (Not yet implemented)
This command is used for configuration management. It is recomended to use register to register/update commands. The config command is for managing configurations manually take a look at the documentation for details about manual configuration.
Optional Arguments:
-e --export: Export the current configuration file (called ahdconfig.yml
)
-i --import: Import a configuration file; takes the path to the config file as an argument
For a full contribution guide, check the contribution section of the documentation. Also be sure to check the faq before submitting issues.
For any additional questions please submit then through github here (much faster response), or my email kieran@canadiancoding.ca.