diff --git a/src/crap.nim b/src/crap.nim index 88336e8..6afb139 100644 --- a/src/crap.nim +++ b/src/crap.nim @@ -4,37 +4,35 @@ import strutils, times -proc crap*(path: var string) = - var trashHome: string +proc crap*(path: string) = let fullPath = expandFilename(path) - path = extractFilename(fullPath) + let fname = extractFilename(fullPath) - if existsEnv("XDG_DATA_HOME"): - trashHome = joinPath(getEnv("XDG_DATA_HOME"), "Trash") + let trashHome = if existsEnv("XDG_DATA_HOME"): + getEnv("XDG_DATA_HOME") / "Trash" else: - trashHome = joinPath(getHomeDir(), ".local/share/Trash") + getHomeDir() / ".local/share/Trash" - moveFile(fullPath, joinPath(trashHome, "files", path)) + moveFile(fullPath, trashHome / "files" / fname) let t = getTime() - formattedTime = t.format("yyyy-MM-dd") & "T" & t.format("HH:MM:ss") + formattedTime = t.format("yyyy-MM-dd'T'HH:MM:ss") trashInfo = fmt"""[Trash Info] Path={fullPath} DeletionDate={formattedTime}""" - writeFile(joinPath(trashHome, "info", fmt"{path}.trashinfo"), trashInfo) + writeFile(trashHome / "info" / fmt"{fname}.trashinfo", trashInfo) when isMainModule: - var del: string = "" + var del = "" + if paramCount() == 0: + echo("error: specify at least one file") + quit(1) try: - if paramCount() == 0: - echo("error: specify at least one file") - quit(0) - else: - for f in countUp(1, paramCount()): - del = paramStr(f).strip() - crap(del) + for f in countUp(1, paramCount()): + del = paramStr(f).strip() + crap(del) except OSError: - echo("error: no such file or directory") - quit(0) + echo("error: no such file or directory: " & del) + quit(1) \ No newline at end of file