Created
March 15, 2024 11:59
-
-
Save pepoluan/2e28ae913ff4f378a9aa923690dfcad2 to your computer and use it in GitHub Desktop.
Linux kernel config sorter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
# | |
# Copyright (C) 2024, Pandu POLUAN | |
import fileinput | |
import re | |
RE_CMT = re.compile(r"(\s*#\s*)?(?P<knob>CONFIG.*)") | |
def main() -> None: | |
conf_lines: dict[str, str] = {} | |
with fileinput.input(encoding="utf-8") as fin: | |
for line in fin: | |
line = line.strip() | |
if not line: | |
continue | |
if not (m := RE_CMT.match(line)): | |
continue | |
conf_lines[m.group("knob")] = line | |
for _, line in sorted(conf_lines.items()): | |
print(line) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment