Skip to content

Instantly share code, notes, and snippets.

@pepoluan
Created March 15, 2024 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepoluan/2e28ae913ff4f378a9aa923690dfcad2 to your computer and use it in GitHub Desktop.
Save pepoluan/2e28ae913ff4f378a9aa923690dfcad2 to your computer and use it in GitHub Desktop.
Linux kernel config sorter
#!/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