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 5bd64e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 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
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 5bd64e4

Please sign in to comment.