Unleash the Power of Zsh: Simplify Shell Scripting with CMDS-FRAMEWORK
Tired of wrestling with boilerplate code when writing shell scripts? Do you long for argument parsing, auto-completion, and organized script management without sacrificing the speed and agility of shell scripting? The CMDS-FRAMEWORK (cmds) is your answer. This Zsh framework dramatically simplifies shell scripting, letting you focus on solving problems, not fighting syntax.
What is CMDS-FRAMEWORK?
CMDS is a Zsh framework designed to streamline shell script development. Addressing the common pitfalls of shell scripting—lack of argument parsing, messy organization, and absence of auto-generated documentation—cmds offers a powerful yet simple alternative.
Instead of resorting to more complex languages like Go (and losing the inherent benefits of shell scripting in the process), cmds integrates directly into Zsh. This integration allows you to write scripts with built-in argument parsing, nested subcommands, completion capabilities, and more, all with minimal effort.
Why Choose CMDS for Your Shell Scripts?
- Rapid Development: Maintain the speed of shell scripting while adding robust features.
- Argument Parsing & Validation: Automatically parses arguments into variables, ensuring required arguments are provided.
- Auto-Completion: Tab completion "just works," including help flags.
- Organization: Scripts are easily organized with nested subcommands.
- Reduced Boilerplate: The framework mandates minimal boilerplate, letting you focus on your script's logic.
Key Features of CMDS-FRAMEWORK
- Argument Parsing: The
args
array allows for argument parsing, completion, and validation. - Automatic Variable Creation: Arguments are automatically converted to global variables for easy access.
- Description & Help Generation: Easily define short descriptions (
desc
) and long-form help texts (help
) for your scripts. - Argument Forwarding: Seamlessly forward arguments to other binaries using the
$forwarded
array.
Getting Started with CMDS: A Quick Walkthrough
-
Source
.lib.sh
: Addsource .lib.sh
to yourzshrc
file. -
Create Subcommands: Make new folders for your subcommands within the cmds directory. Tab completion will automatically recognize your new subcommand.
-
Describe Subcommands: Add a
.description
file within each subcommand directory, defining thedesc
variable. -
Create Commands: Add scripts within the subcommand directories. Define
desc
,args
, andhelp
variables, and anexecute
function. -
Run Your Scripts: Execute your scripts with automatic argument parsing and validation.
Writing CMDS Scripts: The Essentials
Every CMDS script must define three key variables:
desc
: A short description of the script.args
: An array of strings containing argument specifications. The format is--{flag}:[options]{description}
.help
: An array of two strings: the script name and a long-form description.
Additionally, each script must define an execute
function, the heart of your script's logic.
Demystifying the Magic: How CMDS Works
The CMDS-FRAMEWORK leverages the power of Zsh by sourcing script files, loading their variables and arguments into the environment. The execute
function has access to variables defined in both the script and .lib.sh
, creating a seamless development experience.
Advanced CMDS Techniques
- Leveraging
$CMDS_DIR
: Access the path to the cmds directory using$CMDS_DIR
to reference files relative to your scripts. - Utilizing Logging Functions: Use
lib_error
,lib_info
, andlib_warning
for consistent logging within your scripts. - Argument Forwarding: Pass arguments directly to underlying binaries using the
--
separator and the$forwarded
array. - Description & Help Generation: Easily define short descriptions (
desc
) and long-form help texts (help
) for your scripts.
Take Control of Your Shell Scripting Workflow
CMDS-FRAMEWORK empowers you to write robust, maintainable, and well-organized shell scripts with minimal boilerplate. Embrace the power of Zsh and transform your scripting workflow today! Stop struggling with the limitations of traditional shell scripting and unlock a new level of efficiency and clarity with cmds.