Skip to content

Commit

Permalink
fix: sleep after smashfetch
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukinoko-kun committed Sep 29, 2024
1 parent 0446cd9 commit 37e6c49
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func getConfigFile() *smashConfig {
c.InteractivePrompt = "${Color.FgHiBlack}$USER@$PWD\t$DEV${Color.Reset}\n${Color.FgBlue}❯${Color.Reset} "
c.LogPrompt = "${Color.FgHiBlack}$PWD${Color.Reset} "
c.Alias["l"] = []string{"ls", "-l"}
c.OnStart = []string{"smashfetch"}
c.OnStart = []string{"smashfetch", "sleep 500ms"}
e := toml.NewEncoder(f)
if err := e.Encode(c); err != nil {
panic(errors.Join(errors.New("failed to write config file"), err))
Expand Down
16 changes: 16 additions & 0 deletions internal/shell/parser/exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ func (e *exe) smashfetch(stdout io.Writer) error {
return nil
}

func (s *exe) sleep() error {
if len(s.Args) == 0 {
return errors.New("sleep: missing operand")
}
var dur time.Duration
for _, arg := range s.Args {
d, err := time.ParseDuration(arg)
if err != nil {
return err
}
dur += d
}
time.Sleep(dur)
return nil
}

const loremipsum = `Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.`

func (e *exe) loremipsum(stdout io.Writer) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/shell/parser/shell_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (e *exe) internal(stdin io.Reader, stdout io.Writer, stderr io.Writer) (boo
return true, e.cd()
case "smashfetch":
return true, e.smashfetch(stdout)
case "loremipsum":
return true, e.loremipsum(stdout)
case "sleep":
return true, e.sleep()
default:
return false, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/shell/parser/shell_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (e *exe) internal(stdin io.Reader, stdout io.Writer, stderr io.Writer) (boo
return true, e.cd()
case "smashfetch":
return true, e.smashfetch(stdout)
case "loremipsum":
return true, e.loremipsum(stdout)
case "sleep":
return true, e.sleep()
case "env":
return true, e.env(stdout)
default:
Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func main() {
_, _ = fmt.Fprintln(os.Stderr, err)
}
}
<-time.After(400 * time.Millisecond)
}

for {
Expand Down

0 comments on commit 37e6c49

Please sign in to comment.