schwrc
v1.0.5
Published
A CLI tool for working with files
Readme
Schwrc CLI
A command-line tool for creating and managing shell aliases and lambda functions.
Installation
# Install globally
yarn global add schwrc
# Or install from local directory
yarn global add file:.Usage
Basic Commands
# Create an alias for the last command
schwrc -a [name]
# Delete an alias or function from .zshrc
schwrc -d [name]
# Generate a shell command for a lambda function
schwrc -l [func] [args...]Creating Aliases
The -a or --alias flag allows you to create an alias for the last command in your shell history:
# Create an alias interactively
schwrc -a
# Create an alias with a specific name
schwrc -a myaliasDeleting Aliases and Functions
The -d or --delete flag lets you remove aliases or functions from your .zshrc file:
# Delete an entry interactively
schwrc -d
# Delete a specific entry
schwrc -d myaliasLambda Functions
The -l or --lambda flag generates a shell command from a JavaScript lambda function:
# Create a lambda function interactively
schwrc -l
# Create a lambda function with arguments
schwrc -l "(args) => args.join(' ')" hello worldThe generated command will be displayed and you'll be prompted to create an alias for it.
Lambda Function Examples
- Join arguments with spaces:
schwrc -l "(args) => args.join(' ')" hello world
# Output: hello world- Convert arguments to uppercase:
schwrc -l "(args) => args.map(arg => arg.toUpperCase()).join(' ')" hello world
# Output: HELLO WORLD- Count arguments:
schwrc -l "(args) => args.length" hello world
# Output: 2- Read a file (using Node.js built-in modules):
schwrc -l "async (args) => { const fs = require('fs'); const content = await fs.promises.readFile(args[0], 'utf-8'); return content; }" file.txtSuppressing Yarn Output
Use the --no-yarn flag to suppress yarn output:
schwrc --no-yarn -l "(args) => args.join(' ')" hello worldHow It Works
Alias Creation: The tool reads your shell history to get the last command and creates an alias in your
.zshrcfile.Lambda Functions: The tool generates a Node.js command that executes your lambda function with the provided arguments. The generated command can be aliased for future use. Node.js built-in modules (like
fs,path, etc.) can be accessed usingrequire().Interactive Mode: When no arguments are provided for interactive options (like
-aor-l), the tool will prompt you for input.
Requirements
- Node.js 14 or higher
- Yarn or npm
- Zsh shell
Development
# Install dependencies
yarn install
# Build the project
yarn build
# Run tests
yarn testLicense
MIT
