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.3.0
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
Built Distribution
File details
Details for the file sort_lines-0.3.0.tar.gz
.
File metadata
- Download URL: sort_lines-0.3.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e2a70f9c562ca400f8b1bfef313bd469d933d7a6dcee0c3cc01551fe0dfd70b |
|
MD5 | 68d9535d7ffb9b88bee84989236b706f |
|
BLAKE2b-256 | 2a22bb06fb4a493219215b4ccdc81538880056350b70b6051b6b649660e1cd81 |
File details
Details for the file sort_lines-0.3.0-py2.py3-none-any.whl
.
File metadata
- Download URL: sort_lines-0.3.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.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6600b1129de11157d1e0f2e16e8ae4c09a7bd70738194600350135207f35077c |
|
MD5 | 69ff7153c0f5850fe60a2e2c944c3135 |
|
BLAKE2b-256 | 03cdc4cdc76e8bd30147a44ad1bdb6ad20cd879338dabb03dba129ff987a0ea2 |