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) {
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)
}
}
if err != nil {
log.Printf("%s: %s", path, err)
} else {
log.Printf("No such directory: %s", cleanPath)
os.Exit(3)
}
}
histAdd(histFile, cleanPath)
fmt.Printf("%s %s", outString, cleanPath)
os.Exit(0)