From 1e3d3a211d7e3b329c76fd814d25aa9cf2f0f2c7 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 12 Oct 2023 06:17:38 -0600 Subject: [PATCH] Fix directory exist logic --- cdhist.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cdhist.go b/cdhist.go index a9c1656..822d4ae 100644 --- a/cdhist.go +++ b/cdhist.go @@ -103,17 +103,21 @@ func DirAliases(aliasFile string) map[string]string { func cd(histFile, aliasFile, outString, path string) { cleanPath, err := dir.Sanitize(path) + if err != nil { + log.Printf("%s: %s", path, err) + os.Exit(3) + } + if ! dir.Exist(cleanPath) { a := DirAliases(aliasFile) p, prs := a[path] if prs { cleanPath, err = dir.Sanitize(p) + } else { + log.Printf("No such directory: %s", cleanPath) + os.Exit(3) } } - if err != nil { - log.Printf("%s: %s", path, err) - os.Exit(3) - } histAdd(histFile, cleanPath) fmt.Printf("%s %s", outString, cleanPath) os.Exit(0)