hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/init_c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-08-30 18:24:10 +0200
committerhachem <im@hachem.wtf>2026-08-30 18:24:10 +0200
commitaf022e654ec50dff762ae4a211cd8f09aab82ee5 (patch)
tree4a689a9ef78f37c15915bdbef1f918434394995e /.local/bin/init_c
parentf3e8791940e23892d8260b3a7cbdeb32f4b29054 (diff)
add: update nvim
Diffstat (limited to '.local/bin/init_c')
-rwxr-xr-x.local/bin/init_c168
1 files changed, 0 insertions, 168 deletions
diff --git a/.local/bin/init_c b/.local/bin/init_c
deleted file mode 100755
index 9e570b5..0000000
--- a/.local/bin/init_c
+++ /dev/null
@@ -1,168 +0,0 @@
-#!/usr/bin/env python3
-
-"""
-init_c - small makefile project generator.
-
-a small dumb script cause i dont want to keep
-writing makefiles for small dumb c projects.
-
-Author: hachem
-Version: 0.1.0
-"""
-
-from pathlib import Path
-import subprocess
-import questionary
-
-
-def ask_project_name():
- return questionary.text(
- "Project name:",
- validate=lambda value: (
- True
- if value and not Path(value).exists()
- else "Project already exists or name is empty."
- ),
- ).ask()
-
-
-def generate_makefile(project, use_intermediate):
- target_dir = "bin"
-
- if use_intermediate:
- obj_dir = "bin-int"
- else:
- obj_dir = "bin"
-
- target = f"{target_dir}/{project}"
-
- return f"""CC := clang
-
-CFLAGS := -Wall -Wextra -Werror -pedantic -std=c2y -Isrc
-LDFLAGS :=
-
-TARGET := {target}
-SRC := $(wildcard src/*.c)
-OBJ := $(SRC:src/%.c={obj_dir}/%.o)
-
-all: $(TARGET)
-
-$(TARGET): $(OBJ)
-\t@mkdir -p {target_dir}
-\t$(CC) $^ -o $@ $(LDFLAGS)
-
-{obj_dir}/%.o: src/%.c
-\t@mkdir -p {obj_dir}
-\t$(CC) $(CFLAGS) -c $< -o $@
-
-clean:
-\trm -rf bin bin-int
-
-.PHONY: all clean
-"""
-
-
-def main():
- project = ask_project_name()
-
- if project is None:
- return
-
- options = questionary.checkbox(
- "Options:",
- choices=[
- questionary.Choice(
- "Initialize git",
- value="git",
- checked=True,
- ),
- questionary.Choice(
- "Use separate intermediate directory",
- value="intermediate",
- ),
- questionary.Choice(
- "Ignore clangd files",
- value="clangd_ignore",
- checked=True,
- ),
- ],
- ).ask()
-
- if options is None:
- return
-
- use_git = "git" in options
- use_intermediate = "intermediate" in options
- use_clangd_ignore = "clangd_ignore" in options
-
- root = Path(project)
- root.mkdir()
- (root / "src").mkdir()
-
- makefile = generate_makefile(
- project,
- use_intermediate,
- )
-
- (root / "Makefile").write_text(makefile)
-
- (root / "src" / "main.c").write_text(
- """#include <stdio.h>
-
-int main(void)
-{
- puts("type shi");
-}
-"""
- )
-
- ignored = []
-
- if use_intermediate:
- ignored.extend([
- "bin/",
- "bin-int/",
- ])
- else:
- ignored.append("bin/")
-
- if use_clangd_ignore:
- ignored.extend([
- "",
- ".clangd",
- "compile_flags.txt",
- "compile_commands.json",
- ])
-
- if ignored:
- (root / ".gitignore").write_text(
- "\n".join(ignored) + "\n"
- )
-
- if use_git:
- try:
- subprocess.run(
- ["git", "init"],
- cwd=root,
- check=True,
- stdout=subprocess.DEVNULL,
- )
- except FileNotFoundError:
- # legit how bro
- print("Warning: git is not installed.")
-
- print()
- print(f"✔ Created {project}")
- print()
-
- try:
- subprocess.run(
- ["tree", "-a", "--dirsfirst", "-I", ".git", project],
- check=False,
- )
- except FileNotFoundError:
- print("(tree is not installed)")
-
-
-if __name__ == "__main__":
- main() \ No newline at end of file