Refactored justfile for more reliability

This commit is contained in:
2026-04-07 12:53:21 +01:00
parent ea35fe339b
commit c4d74f74b8
4 changed files with 330 additions and 242 deletions
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ typer rich ])"
import typer
import subprocess
from pathlib import Path
import mimetypes
def is_text_file(filepath):
mime_type, _ = mimetypes.guess_type(filepath)
if mime_type:
return mime_type.startswith("text/")
try:
with open(filepath, "tr") as f:
f.read(1024)
return True
except (UnicodeDecodeError, IsADirectoryError):
return False
app = typer.Typer()
@app.command()
def edit(target: Path = typer.Argument(..., help="File or directory to edit")):
if not target.exists():
subprocess.run(["nvim", str(target)])
return
if target.is_dir():
subprocess.run(["yazi", str(target)])
return
if is_text_file(str(target)):
subprocess.run(["nvim", str(target)])
else:
subprocess.run(["heh", str(target)])
if __name__ == "__main__":
app()