Fix directory exist logic

master
Bryan 2023-10-12 06:17:38 -06:00
parent cbaceb03ce
commit 1e3d3a211d
1 changed files with 8 additions and 4 deletions

View File

@ -103,17 +103,21 @@ func DirAliases(aliasFile string) map[string]string {
func cd(histFile, aliasFile, outString, path string) { func cd(histFile, aliasFile, outString, path string) {
cleanPath, err := dir.Sanitize(path) cleanPath, err := dir.Sanitize(path)
if err != nil {
log.Printf("%s: %s", path, err)
os.Exit(3)
}
if ! dir.Exist(cleanPath) { if ! dir.Exist(cleanPath) {
a := DirAliases(aliasFile) a := DirAliases(aliasFile)
p, prs := a[path] p, prs := a[path]
if prs { if prs {
cleanPath, err = dir.Sanitize(p) cleanPath, err = dir.Sanitize(p)
} } else {
} log.Printf("No such directory: %s", cleanPath)
if err != nil {
log.Printf("%s: %s", path, err)
os.Exit(3) os.Exit(3)
} }
}
histAdd(histFile, cleanPath) histAdd(histFile, cleanPath)
fmt.Printf("%s %s", outString, cleanPath) fmt.Printf("%s %s", outString, cleanPath)
os.Exit(0) os.Exit(0)