Fixed bugs and improved justfile UX

This commit is contained in:
2026-04-07 13:18:12 +01:00
parent 2ce738fc0e
commit 75705ebced
4 changed files with 38 additions and 17 deletions
+8 -4
View File
@@ -5,21 +5,24 @@ from pathlib import Path
import mimetypes
def is_text_file(filepath):
def is_text_file(filepath: str):
mime_type, _ = mimetypes.guess_type(filepath)
if mime_type:
return mime_type.startswith("text/")
try:
with open(filepath, "tr") as f:
f.read(1024)
with open(filepath, "rb") as f:
chunk = f.read(1024)
if b"\0" in chunk:
return False # Null bytes usually mean binary
return True
except (UnicodeDecodeError, IsADirectoryError):
except IsADirectoryError:
return False
app = typer.Typer()
@app.command()
def edit(target: Path = typer.Argument(..., help="File or directory to edit")):
if not target.exists():
@@ -35,5 +38,6 @@ def edit(target: Path = typer.Argument(..., help="File or directory to edit")):
else:
subprocess.run(["heh", str(target)])
if __name__ == "__main__":
app()