maid-cleaning-cli
v0.0.9
Published
maid will clean for you
Downloads
3
Readme
Maid - Your Lightweight CLI Utility for Keeping Directories Clean and Structured
Organizing directories can become messy over time. Maid is here to help. Define where files should go, and Maid will take care of it. Listing files, moving files, and maintaining clean directories - Maid is here for you!
Installation
npm install maid-cleaning-cli -g
Usage
Listing Contents of a Directory
To list all files and sub-directories in a certain directory, just navigate to said directory and tell maid to list:
maid list
The output will be color-coded. Blue represents files, and red represents sub-directories.
To specify what to list, list
accepts two flags:
-f
or--files
to show files-d
or--dirs
to show directories
When using the flags, a color-coded headline will be printed above the actual result. Either Directories in current directory
or Files in current directory
.
Cleaning a directory
To clean a directory, just simply navigate to the messy directory and tell maid to clean:
maid clean
By default maid will not start cleaining without you instructing what needs cleaing and what must not be cleaned. For the clean command to take action, a .maidrc
-file is required. If no config is present, an error with instructions will be printed - so don't worry, maid won't go ahead and move your files around without you knowing what you are doing.
Example
With the following rule in my .maidrc
:
---
cleanRules:
- { pattern: '^Test', fileExtension: '.txt', dirName: 'test_txt_files' }
Every file with a name starting with "Test"
and a file extention of ".txt"
will be moved to a folder test_txt_files
.
Cleaning globally
To add some more efficiency, maid can also execute all rules that have specified values for applyInDir with one single command:
maid clean -g
The important distinction to make here
A rule is defined as global when no values are present for applyInDir
. This means a rule is applicable in every directory by using maid clean
. Cleaning globally on the other hand refers to executing all defined rules that have specified directories in which the rules can be applied. In other words: only rules with a directory-safeguard will be applied when executing a global clean by using maid clean -g
Example
Given the following clean rules in .maidrc
:
{
"cleanRules": [
{
"fileExtension": [".txt"],
"dirName": "Text_Documents",
"applyInDir": [
"/Users/<username>/Desktop/testdir",
"/Users/<username>/Desktop/testdir2"
]
},
{
"fileExtension": [".pdf"],
"dirName": "PDFs",
"applyInDir": [
"/Users/<username>/Desktop/testdir3",
"/Users/<username>/Desktop/testdir4"
]
}
]
}
And the test directories testdir
, testdir2
, testdir4
in /Users/<username>/Desktop
. Each directory contains the same test files:
A global clean called from /Desktop
will show the following result:
For each rule, all directories specified in applyInDir
are cleaned according to the rule.
.maidrc Configuration
To instruct Maid on what to clean, create a .maidrc
configuration file on your machine. Maid will use it when running.
For now, the config file only supports one property: cleanRules
.
cleanRules
is an array of objects that define the rules for Maid to clean. Each object represents one rule, indicating what to clean and under which conditions.
pattern (String)
: A regular expression to describe how the filename should look (e.g."^Test"
will filter all files starting with "Test")fileExtension (String-Array)
: A list of file extension to limit the files to be cleaned (e.g.".png"
- include the.
)applyInDir (String-Array)
: A list of paths in which the rule can be applied. If applyInDir is no present, the rule is global and applicable in every folderdirName (String)
: When cleaning files, maid will move them to a folder, that can be specified with this string (e.g."/screenshots/images"
)
pattern
, fileExtension
and applyInDir
will be evaluated with AND
-logic, so the rule
{
"pattern": "^Testfile",
"fileExtension": [".png"],
"dirName": "testfiles",
"applyInDir": ["/Users/<username>/Desktop"]
}
will only move files to a folder called testfiles
, if the following conditions are all met:
- if the filename starts with
"Testfile"
- if the file has the extension
.png
- the current directory is
/Users/<username>/Desktop
If neither pattern
nor fileExtension
is defined, the rule will not trigger and do nothing.
git repo safeguard
As an additional safeguard to prevent accidentally messing up the structure of git repositories, maid has a build in check when running clean
. If current directory is a git repository, maid will ask if you wish to continue.
Getting Information about Saved Configuration
To retrieve information about the saved .maidrc
configuration, use the following command:
maid config
For specific information, use these flags:
p
or--path
: Get the path to the config filer
or--cleanRules
: Get all saved rules from the configd
or--rulesForDir
: Get rules specific to the current directory
Creating Configuration
If no configuration is present, maid can even initiate configuration for you, just call config with the flag -i
or --init
maid config --init
This command will guide you through the process of creating a .maidrc configuration file. If the configuration file already exists, the command will let you know.
Adding a Rule to Configuration
To add a rule to the configuration, use the following command:
maid config --addRule
This command will prompt you to enter details for the rule you want to add. You will need to provide the following information:
- Pattern (required if no fileExtension is specified): A regular expression to match filenames.
- File Extension (required if no pattern is specified): A list of file extensions separated by commas (e.g., .txt, .jpg).
- Apply in Directory (optional): Specify one or more directory paths where the rule should apply.
- Directory Name (required): The name of the directory where matching files will be moved.
The addRule
command allows you to define specific cleanup rules according to your needs.
Example:
Suppose you want to add a rule to move all files starting with "Report"
and having the extensions .docx
and .pdf
to a directory called reports
. You can use the following command:
maid config --addRule
Then provide the following information in the prompts:
- Pattern:
^Report
- File Extension:
.docx, .pdf
- Apply in Directory:
(leave empty for global rule)
- Directory Name:
reports
This will create a rule that moves files matching the specified pattern and extensions to the reports directory.