~rootmos/scripts

b1648ba0e6282091303ea39077154e3c14374622 — Gustav Behm a month ago 92cad45 + eb3c766
Merge branch 'readme'
8 files changed, 125 insertions(+), 2 deletions(-)

M .build.yml
A .gitignore
A Makefile
M README.md
A README.preamble.md
M is-clean
A scripts.py
A scripts.toml
M .build.yml => .build.yml +3 -0
@@ 4,6 4,9 @@ packages:
  - shellcheck
  - py3-pylint
tasks:
  - readme: |
      cd scripts
      ./is-clean -m README.md
  - check: |
      cd scripts
      ./check

A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
*.snippet.md

A Makefile => Makefile +5 -0
@@ 0,0 1,5 @@
README.md: README.preamble.md README.snippet.md
	cat $^ > $@

README.snippet.md: scripts.toml scripts.py 
	./scripts.py $@

M README.md => README.md +16 -1
@@ 1,3 1,18 @@
# rootmos' scripts

[![builds.sr.ht status](https://builds.sr.ht/~rootmos/scripts.svg)](https://builds.sr.ht/~rootmos/scripts?)
[![builds.sr.ht status](https://builds.sr.ht/~rootmos/scripts.svg)](https://builds.sr.ht/~rootmos/scripts)

* [k](k): Remember kommon commands by directory by keeping them in a .k file
* [dorker](dorker): After an embarrasing number of misspelings of `dorker` (I mean `docker`) this is is my resulting convenience wrapper
* [cult](cult): How I endure the [cult](https://crates.io/) of [Rust](https://www.rust-lang.org/)
* [downloads](downloads): List or move recent files from the usual ~/Downloads directory
* [term](term): Run a program in a new terminal or in the current terminal if available
* [build-info](build-info): Figure out the information about the current environment and render it into a shell environment variables file, C constants or a Lua table
* [theft](theft): [Steal this script](https://en.wikipedia.org/wiki/Steal_This_Album!)
* [aspect-ratio](aspect-ratio): Force the aspect ratio of an X window
* [is-clean](is-clean): Check if git and/or make considers a file to be clean. (NB this script is used to make sure the `README.md` is kept updated from this its `scripts.toml` source.)
* [include](include): Run a c-style @include-pas on a file
## ArchLinux management scripts
* [clean](clean): Cleanup pacman cached, orphaned and/or explicitly installed packages, and coredumps
* [update](update): Update ArchLinux packages and rust, haskell, ocaml caches and nvim plugins
* [pkg-add](pkg-add): Install or die package(s) or file(s)

A README.preamble.md => README.preamble.md +4 -0
@@ 0,0 1,4 @@
# rootmos' scripts

[![builds.sr.ht status](https://builds.sr.ht/~rootmos/scripts.svg)](https://builds.sr.ht/~rootmos/scripts)


M is-clean => is-clean +4 -1
@@ 64,7 64,10 @@ def is_clean(path, make=False, root=None, target=None, show_diff=False):

def setup_logger(level, name=None):
    level = level.upper()
    l = logging.getLogger(name=name)
    if isinstance(name, str):
        l = logging.getLogger(name=name)
    else:
        l = name
    l.setLevel(level)

    handler = logging.StreamHandler()

A scripts.py => scripts.py +47 -0
@@ 0,0 1,47 @@
#!/usr/bin/env python3

import os
import sys
import tomllib

script_dir = os.path.dirname(os.path.realpath(__file__))

def run(scripts, o):
    sections = {}
    for k, v in scripts.get("section", {}).items():
        sections[k] = v
        if "scripts" not in v:
            v["scripts"] = {}

    for k, v in scripts.get("scripts", {}).items():
        s = v.get("section") or ""
        section = sections.get(s)
        if section is None:
            section = {"scripts": {}}
            sections[s] = section
        section["scripts"][k] = v

    for _, section in (sorted(sections.items(), key=lambda i: i[0])):
        t = section.get("title")
        if t:
            o.write("## " + t)
            o.write("\n")

        for fn, s in section.get("scripts", {}).items():
            o.write("* ")
            o.write(f"[{fn}]({fn})")
            d = s.get("description")
            if d:
                o.write(": ")
                o.write(d)
            o.write("\n")

if __name__ == "__main__":
    with open(os.path.join(script_dir, "scripts.toml"), "rb") as f:
        scripts = tomllib.load(f)

    try:
        with open(sys.argv[1], "w", encoding="utf-8") as o:
            run(scripts, o)
    except IndexError:
        run(scripts, sys.stdout)

A scripts.toml => scripts.toml +45 -0
@@ 0,0 1,45 @@
[scripts.k]
description = "Remember kommon commands by directory by keeping them in a .k file"

[scripts.dorker]
description = "After an embarrasing number of misspelings of `dorker` (I mean `docker`) this is is my resulting convenience wrapper"

[scripts.cult]
description = "How I endure the [cult](https://crates.io/) of [Rust](https://www.rust-lang.org/)"

[scripts.downloads]
description = "List or move recent files from the usual ~/Downloads directory"

[scripts.term]
description = "Run a program in a new terminal or in the current terminal if available"

[scripts.build-info]
description = "Figure out the information about the current environment and render it into a shell environment variables file, C constants or a Lua table"

[scripts.theft]
description = "[Steal this script](https://en.wikipedia.org/wiki/Steal_This_Album!)"

[scripts.aspect-ratio]
description = "Force the aspect ratio of an X window"

[scripts.is-clean]
description = "Check if git and/or make considers a file to be clean. (NB this script is used to make sure the `README.md` is kept updated from this its `scripts.toml` source.)"

[scripts.include]
description = "Run a c-style @include-pas on a file"


[section.archlinux]
title = "ArchLinux management scripts"

[scripts.clean]
section = "archlinux"
description = "Cleanup pacman cached, orphaned and/or explicitly installed packages, and coredumps"

[scripts.update]
section = "archlinux"
description = "Update ArchLinux packages and rust, haskell, ocaml caches and nvim plugins"

[scripts.pkg-add]
section = "archlinux"
description = "Install or die package(s) or file(s)"