diff --git a/README.md b/README.md index ae46afa..2b36d22 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,7 @@ $ jj * Tips: Use `tab` to complete dir. * Note: `mruHist` stored abs path. -* Use `ctrl-z` to multi-selection, -* but to `open2cd` only first one. +* Use `ctrl-z` if to multi-select, and/but to `open2cd` only the last one. ## Options diff --git a/go.mod b/go.mod index afbfe48..f5807bc 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( ) require ( - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/rivo/uniseg v0.4.4 // indirect golang.org/x/sync v0.4.0 // indirect golang.org/x/sys v0.13.0 // indirect diff --git a/go.sum b/go.sum index 91477f2..b994376 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,8 @@ github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= diff --git a/jj b/jj index 3068bde..7fca7d1 100755 Binary files a/jj and b/jj differ diff --git a/main.go b/main.go index 8a73720..53399e1 100644 --- a/main.go +++ b/main.go @@ -110,7 +110,6 @@ func getHomeDir() string { if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) - // shane: better return nil (vs exit) instead ? } return userHome } @@ -118,23 +117,19 @@ func getHomeDir() string { func readFs(path string) []string { f, err := os.Open(path) if err != nil { - // fmt.Fprintln(os.Stderr, err) - // os.Exit(1) + if os.IsNotExist(err) { + return []string{} + } return nil - // shane: mostly failed if not existed ? } defer f.Close() tmp := []string{} sc := bufio.NewScanner(f) for sc.Scan() { - // fmt.Println(sc.Text()) tmp = append(tmp, sc.Text()) } if err := sc.Err(); err != nil { - // fmt.Fprintln(os.Stderr, err) - // os.Exit(1) return nil - // shane: somehow failed - return nil whatever ? } return tmp } @@ -145,8 +140,8 @@ func filesIfMru() []string { if !mruHist { return files } - tmp := readFs(getHomeDir() + "/" + mruStore) tmpLen := 0 + tmp := readFs(getHomeDir() + "/" + mruStore) if tmp != nil { tmpLen = len(tmp) } @@ -154,7 +149,7 @@ func filesIfMru() []string { tmp2 := []string{} if tmpLen > 0 { for i := tmpLen - 1; i >= 0; i-- { - // shane: to make mru list showed as rel path of cwd ? + // shane: to make mru list showed as rel path of cwd? // if rl_p, err := filepath.Rel(cwd, tmp[i]); err == nil { // tmp2 = append(tmp2, rl_p) // } else { @@ -162,8 +157,6 @@ func filesIfMru() []string { // } tmp2 = append(tmp2, tmp[i]) } - } else { - return nil } return tmp2 } @@ -179,11 +172,9 @@ func filterIfDirOnly(fs []string) []string { for _, f := range fs { fi, err := os.Stat(f) if err != nil { - // fmt.Fprintln(os.Stderr, err) - // os.Exit(1) continue - // XXX: may fail - just ignore such ? - // shane: mostly looks due to auth ?! + // XXX: may fail? just ignore such? + // shane: mostly looks due to auth? } if fi.IsDir() { tmp = append(tmp, f) @@ -930,7 +921,7 @@ loop: if root != "" && !mruHist { for _, f := range selected { fArg = append(fArg, filepath.Join(root, f)) - // XXX: should use 'cwd' instead of 'root' ? + // XXX: should use 'cwd' instead of 'root'? } } else { fArg = append(fArg, selected...) @@ -994,7 +985,7 @@ loop: fmt.Fprintln(os.Stderr, err) os.Exit(1) } - } else { + } else { // shane: was this possible unexpected case? // f, err := os.Create(getHomeDir()+"/"+mruTmpFs) f, err := os.OpenFile(getHomeDir()+"/"+mruTmpFs, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600) if err != nil {