Skip to content

Latest commit

 

History

History
174 lines (135 loc) · 3.39 KB

README.md

File metadata and controls

174 lines (135 loc) · 3.39 KB

Interactive Sort

An interactive sorting utility for text lines with various sorting options, similar to the Unix sort command but with real-time display as you type.

Features

  • Interactive sorting: See your data sorted in real-time as you type each line
  • Multiple sorting modes:
    • Alphabetical (default)
    • Numeric (-n)
    • Human-readable numbers (-H) - handles 1K, 2M, etc.
    • Month-based (-M) - sorts by month abbreviations (JAN, FEB, etc.)
  • Sorting options:
    • Case-insensitive sorting (-f)
    • Reverse sorting (-r)
    • Unique filtering (-u)
    • Ignore non-printing characters (-i)
    • Field separator support (-t)

Installation

From PyPI (recommended)

pip install interactive-sort

From source

git clone https://github.com/MightyHelper/interactive-sort.git
cd interactive-sort
pip install -e .

Usage

After installation, you can run the tool using the interactive-sort command:

interactive-sort [OPTIONS]

Options

-f, --ignore-case          Fold lower case to upper case characters
-i, --ignore-nonprinting   Consider only printable characters
-M, --month-sort          Compare (unknown) < 'JAN' < ... < 'DEC'
-H, --human-numeric-sort  Compare human readable numbers (e.g., 2K 1G)
-n, --numeric-sort        Compare according to string numerical value
-r, --reverse             Reverse the result of comparisons
-u, --unique              Output only the first of an equal sequence
-t, --field-separator     Use FIELD as the field separator when finding an ordering key

Examples

Basic usage

interactive-sort

Type lines of text, and they will be sorted alphabetically in real-time. Press Ctrl+D (or Ctrl+Z then Enter on Windows) to finish.

Numeric sorting

interactive-sort -n

Sort lines numerically:

Input: 100, 20, 3
Output: 3, 20, 100

Human-readable numeric sorting

interactive-sort -H

Sort human-readable numbers:

Input: 1G, 500M, 2K
Output: 2K, 500M, 1G

Month sorting

interactive-sort -M

Sort by month abbreviations:

Input: MAR data, JAN data, FEB data
Output: JAN data, FEB data, MAR data

Case-insensitive and reverse sorting

interactive-sort -fr

Sort case-insensitively and in reverse order.

Field separator

interactive-sort -t,

Sort by the first field when using comma as separator:

Input: banana,fruit | apple,fruit | cherry,fruit
Output: apple,fruit | banana,fruit | cherry,fruit

Running as a Python module

You can also run the tool as a Python module:

python -m interactive_sort [OPTIONS]

Development

Setting up development environment

  1. Clone the repository:

    git clone https://github.com/MightyHelper/interactive-sort.git
    cd interactive-sort
  2. Install in development mode:

    pip install -e .
  3. Install development dependencies:

    pip install tox ruff pytest

Running tests

Run tests using tox (tests multiple Python versions):

tox

Run tests with pytest directly:

pytest

Code formatting and linting

Format code:

ruff format

Check formatting:

ruff format --check

Lint code:

ruff check

License

MIT License. See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.