Fix directory exist logic
parent
cbaceb03ce
commit
1e3d3a211d
12
cdhist.go
12
cdhist.go
|
|
@ -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)
|
||||||
|
os.Exit(3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
log.Printf("%s: %s", path, err)
|
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue