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.

pre-commit

This tool can be used with pre-commit:

repos:
-   repo: https://github.com/samueljsb/sort-files
    rev: v0.1.0
    hooks:
    -   id: sort-files

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.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

sort_lines-0.1.0-py2.py3-none-any.whl (3.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: sort_lines-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for sort_lines-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ed34c184675c52f4e4f01ff8d351a837488271f15569aa841fb12624fcfc421
MD5 d550689593b90f4320599ba54ec2754f
BLAKE2b-256 9c55ecaabbffd52a6346a50964b3436987ad901cc4daf7911deb828cc231b4db

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sort_lines-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for sort_lines-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5ab86c42b8e0ca244ac6f4a980c4ee99174883949d90aa148c02ba612ecbd9cd
MD5 52930b19235ce0704792a4423cde17c3
BLAKE2b-256 94aeaedd20910105d206cf966c4f93807eacd98ed7485f4c25783b9f73fb0ba5

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