Skip to main content

alphabetize lines in files

Project description

sort lines

Alphabetize lines in a file.

This tool uses leading whitespace to delimit the lines that should be alphabetized. It is intended for use with Python code but should work with anything that has consistent indentation.

usage

Indicate that some lines should be alphabetized by including a comment on the line above (the comment must include # pragma: alphabetize).

# names.py
names = [  # pragma: alphabetize
    'Alice',
    'Bob',
    'Charlie',
    'David',
    'Eve',
]

Run this tool on the file:

sort-lines names.py

Indentation will be used to decide which lines need to be sorted. The first line after the pragma comment will set the indentation level and every subsequent line with the same amount of indentation will be included in the sorting. The first line with a different indentation(including blank lines) will indicate the end of the sorted lines.

Lines can be sorted case-insensitively by using the [ci] or [case-insensitive] options:

# names.py
names = [  # pragma: alphabetize[case-insensitive]
    'Alice',
    'bob',
    'Charlie',
    'david',
    'Eve',
]

Or by passing --case-insensitive on the command line.

pre-commit

This tool can be used with pre-commit:

repos:
-   repo: https://github.com/samueljsb/sort-lines
    rev: v0.1.2
    hooks:
    -   id: sort-lines

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sort_lines-0.2.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

sort_lines-0.2.0-py2.py3-none-any.whl (4.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sort_lines-0.2.0.tar.gz.

File metadata

  • Download URL: sort_lines-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sort_lines-0.2.0.tar.gz
Algorithm Hash digest
SHA256 90bae1ac45d8b27b6eb163c8e7fbf944b858f6ac76582c5ef0d86dc3812b7f10
MD5 40f516981238341c5c63e1f89481412a
BLAKE2b-256 8d8c4d2ab0cfb852c67bff2b0de24728d7fadaac4a609183b7c04d134d52bae1

See more details on using hashes here.

File details

Details for the file sort_lines-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sort_lines-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for sort_lines-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8d5f8d9a0d0afbf7db49ef7783655ffa6cca3c8101af3797d4b4bc27a66607bc
MD5 40755c247a984b53ee799f3c59bc595e
BLAKE2b-256 f1914a70d04fe18d6b46fdf4e7ba7d79cec901ae9993dc72a87852083439b513

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page