Skip to content

Commit

Permalink
fix: zu chdir history
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinoko-kun committed Oct 2, 2024
1 parent d5a1be0 commit d05b845
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
35 changes: 28 additions & 7 deletions internal/shell/parser/exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ func pushDir(p string) error {
}
}

func pushDirZu(p string) error {
cdHistoryMut.Lock()
defer cdHistoryMut.Unlock()

wd, err := os.Getwd()
if err != nil {
return err
}
cdHistory = append(cdHistory, wd)

if err := zu.To(p); err != nil {
return err
} else {
_ = os.Setenv("PWD", p)
return nil
}
}

func (e *exe) cd() error {
switch len(e.Args) {
case 0:
Expand All @@ -251,14 +269,15 @@ func (e *exe) cd() error {
}
}

func (e *exe) z() error {
func (e *exe) zu() error {
switch len(e.Args) {
case 0:
return pushDir(env.GetUser().HomeDir)
return pushDirZu(env.GetUser().HomeDir)
case 1:
if e.Args[0] == "-c" {
switch e.Args[0] {
case "-c", "--clear":
return zu.Clear()
} else if e.Args[0] == "-l" {
case "-l", "--list":
if l, err := zu.List(); err != nil {
return err
} else {
Expand All @@ -267,11 +286,13 @@ func (e *exe) z() error {
}
return nil
}
} else {
return zu.To(e.Args[0])
case "-":
return popDir()
default:
return pushDirZu(e.Args[0])
}
default:
return errors.New("z: too many operands")
return pushDirZu(strings.Join(e.Args, " "))
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/shell/parser/shell_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (e *exe) internal(stdin io.Reader, stdout io.Writer, stderr io.Writer) (boo
case "cd":
return true, e.cd()
case "zu":
return true, e.z()
return true, e.zu()
case "smashfetch":
return true, e.smashfetch(stdout)
case "sleep":
Expand Down
2 changes: 1 addition & 1 deletion internal/shell/parser/shell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (e *exe) internal(stdin io.Reader, stdout io.Writer, stderr io.Writer) (boo
case "cd":
return true, e.cd()
case "zu":
return true, e.z()
return true, e.zu()
case "smashfetch":
return true, e.smashfetch(stdout)
case "sleep":
Expand Down

0 comments on commit d05b845

Please sign in to comment.