Skip to content

ShubhamSPawade/segre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Segre

A CLI tool to organize (segregate) files into categories.

Segre

npm npm downloads Node.js >= 18 License Coverage GitHub issues GitHub stars GitHub last commit

Features

  • Organize by Category: Automatically sort files into folders like Images, Documents, Audio, Videos, Code, Archives, etc.
  • Organize by Date: Sort files into Year/Month folders based on modification date
  • Recursive Mode: Organize files in subdirectories too (NEW!)
  • Dry Run Mode: Preview what would happen without making changes
  • Interactive Mode: Confirm each file move individually
  • Custom Config: Define your own categories via JSON config file
  • Ignore Patterns: Skip files matching specific patterns
  • Undo Support: Revert the last organization operation
  • Progress Bar: Visual feedback during organization
  • Professional Output: Clean, professional CLI output

Prerequisites

  • Node.js >= 18 (Node 20 LTS recommended)
  • npm >= 8

Installation

Quick Use (No Installation Required)

Run directly using npx - no installation needed:

npx segre ./my-folder

Global Installation

Install once and use anywhere on your system:

npm install -g segre

After global installation, you can use segre command from any directory.

Local Installation (For Development)

# Clone and install locally
npm install
npm link

Usage

Basic Usage

# Organize files in a directory
segre ./my-folder

# Preview changes without moving files
segre ./my-folder --dry-run

# Organize with verbose output
segre ./my-folder --verbose

Recursive Mode

# Organize files in subdirectories too
segre ./my-folder --recursive

# Combine with other options
segre ./my-folder --recursive --dry-run

Organize by Date

# Sort files into Year/Month folders
segre ./my-folder --by-date

Interactive Mode

# Confirm each file move
segre ./my-folder --interactive

Ignore Files

# Ignore specific patterns
segre ./my-folder --ignore "*.log,*.tmp,node_modules"

Custom Categories

# Generate a sample config file
segre init-config

# Use custom categories
segre ./my-folder --config ./segre.config.json

View Categories

# Show default categories
segre categories

# Show custom categories
segre categories --config ./segre.config.json

Undo Last Operation

# Restore files to original locations
segre undo ./my-folder

Options

Option Alias Description
--config <path> -c Path to custom categories config file (JSON)
--dry-run -d Show what would happen without moving files
--interactive -i Ask before moving each file
--by-date -b Organize files by modification date (Year/Month)
--recursive -r Recursively organize files in subdirectories
--ignore <patterns> Comma-separated patterns to ignore
--verbose -v Show detailed output

Commands

Command Description
segre <directory> Organize files in directory
segre undo <directory> Undo last organization
segre categories Show file categories
segre init-config [path] Generate sample config file

Default Categories

  • Archives: .zip, .tar, .gz, .rar, .7z, .bz2, .xz
  • Audio: .mp3, .wav, .flac, .aac, .ogg, .wma, .m4a
  • Code: .js, .ts, .css, .html, .py, .java, .cpp, .c, .h, .jsx, .tsx, .vue, .rb, .go, .rs, .php, .swift, .kt
  • Documents: .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx, .txt, .rtf, .odt, .ods, .odp, .md, .csv
  • Executables: .exe, .msi, .dmg, .app, .deb, .rpm, .sh, .bat, .cmd
  • Fonts: .ttf, .otf, .woff, .woff2, .eot
  • Images: .jpg, .jpeg, .png, .gif, .bmp, .tiff, .svg, .webp, .ico, .raw, .psd, .ai
  • Videos: .mp4, .mkv, .avi, .mov, .wmv, .flv, .webm, .m4v, .mpeg, .mpg
  • Others: Files that don't match any category

Custom Config Example

{
  "Images": [".jpg", ".jpeg", ".png", ".gif", ".webp"],
  "Documents": [".pdf", ".doc", ".docx", ".txt", ".md"],
  "Audio": [".mp3", ".wav", ".flac"],
  "Videos": [".mp4", ".mkv", ".avi"],
  "Code": [".js", ".ts", ".py", ".java"],
  "Archives": [".zip", ".rar", ".7z"],
  "MyCustomCategory": [".custom", ".myext"],
  "Others": []
}

Project Structure

segre/
├── bin/
│   └── segre.js          # CLI entry point
├── src/
│   ├── index.js          # Main exports
│   ├── categories.js     # Category definitions
│   ├── cli.js            # CLI commands
│   ├── config.js         # Config loading
│   ├── logger.js         # Operation logging
│   ├── organizer.js      # Core logic
│   ├── utils.js          # Utility functions
│   └── index.test.js     # Tests
├── package.json
└── README.md

Development

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

License

MIT License - see LICENSE for details.

Author

Shubham Pawade


Made with ❤️ by Shubham Pawade

About

Segre - A CLI tool to automatically organize files by category or date, with dry‑run, interactive, and undo support.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors