master
Bryan 2023-09-26 07:40:33 -06:00
parent b16e75e6a0
commit b7fd6e9eae
2 changed files with 17 additions and 34 deletions

View File

@ -31,7 +31,7 @@ func histAdd(histFile string, newPath string) (error) {
return err
}
if len(paths) == 0 {
path, _ := os.Getwd()
path, err := os.Getwd()
if err == nil {
paths = append(paths, path)
}
@ -122,7 +122,6 @@ func cd(histFile, aliasFile, outString, path string) {
func ReadLines(fileName string) ([]string, error) {
file, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, 0660)
if err != nil {
// log.Print(err)
return nil, err
}
defer file.Close()
@ -171,33 +170,7 @@ func printBashFunc(opts BashFuncOpts) {
return
}
/*
func sanitizePath(path string) string {
switch path {
case "-":
path = os.Getenv("OLDPWD")
case "":
var err error // need to do this because the next line won't work using :=
path, err = os.UserHomeDir()
if err != nil {
log.Printf("No home directory: %s", err)
}
}
path = strings.TrimSpace(path)
path, err := filepath.Abs(path)
if err != nil {
log.Printf("Invalid path:, %s", err)
os.Exit(2)
}
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Printf("%s: No such directory.", path)
log.Printf("%v", DirAliases(aliasFile))
os.Exit(2)
}
return path
}*/
// func cdableVars() bool {
// v := exec.Command("bash", "-i", "-c", "echo $var")

22
main.go
View File

@ -9,7 +9,7 @@ import (
// "cdhist/dir"
)
// must run the following to source the cd bash function
// must run the following to source the cd bash function:
// if type cdhist &>/dev/null; then . <(cdhist -i); fi
var (
@ -39,13 +39,23 @@ func main() {
}
os.Exit(1)
}
flagInit := flag.Bool("i", false, "Creates function to be sourced by bash")
flagList := flag.Bool("l", false, "List cd history without prompting")
flagL := flag.Bool("L", false, "Passed to cd")
flagP := flag.Bool("P", false, "Passed to cd")
flage := flag.Bool("e", false, "Passed to cd")
flagAt := flag.Bool("@", false, "Passed to cd")
flagL := flag.Bool("L", false, "Builtin cd option, passed to cd")
flagP := flag.Bool("P", false, "Builtin cd option, passed to cd")
flage := flag.Bool("e", false, "Builtin cd option, passed to cd")
flagAt := flag.Bool("@", false, "Builtin cd option, passed to cd")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [option] [dir]\n\n", os.Args[0])
fmt.Fprint(flag.CommandLine.Output(), "Change directory and save directory to history.\n")
fmt.Fprint(flag.CommandLine.Output(), "Or show directory history with or without prompt.\n\n")
fmt.Fprint(flag.CommandLine.Output(), " --\tShow history with prompt.\n")
flag.PrintDefaults()
os.Exit(1)
}
flag.Parse()
switch {