Skip to content

Commit

Permalink
none: tidy code a bit
Browse files Browse the repository at this point in the history
Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
  • Loading branch information
Shane-XB-Qian committed Oct 27, 2023
1 parent 7b6ee6d commit 0694c52
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
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=
Expand Down
Binary file modified jj
Binary file not shown.
27 changes: 9 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,26 @@ func getHomeDir() string {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
// shane: better return nil (vs exit) instead ?
}
return userHome
}

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
}
Expand All @@ -145,25 +140,23 @@ func filesIfMru() []string {
if !mruHist {
return files
}
tmp := readFs(getHomeDir() + "/" + mruStore)
tmpLen := 0
tmp := readFs(getHomeDir() + "/" + mruStore)
if tmp != nil {
tmpLen = len(tmp)
}
// shane: to make last mru item showed at the list bottom.
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 {
// tmp2 = append(tmp2, tmp[i])
// }
tmp2 = append(tmp2, tmp[i])
}
} else {
return nil
}
return tmp2
}
Expand All @@ -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)
Expand Down Expand Up @@ -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...)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0694c52

Please sign in to comment.