mirror of
https://github.com/Cian-H/My_NixOS_Config.git
synced 2026-05-09 06:31:42 +01:00
Fixed bugs and improved justfile UX
This commit is contained in:
+8
-4
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user