mirror of
https://github.com/Cian-H/My_NixOS_Config.git
synced 2026-05-09 06:31:42 +01:00
Refactored justfile for more reliability
This commit is contained in:
Executable
+40
@@ -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()
|
||||
Reference in New Issue
Block a user