Skip to content

Commit

Permalink
Keep history of URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mozz100 committed Mar 5, 2019
1 parent 4067f03 commit aab85ab
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions subprocess/subprocess.go
Expand Up @@ -6,6 +6,8 @@ import (
"os/exec"
)

const maxHistory int = 3

// Context contains everything needed - the underlying Cmd and the
// mechanism to terminate it.
type Context struct {
Expand All @@ -22,7 +24,6 @@ type Context struct {
func GetSubprocess(cmd string) *Context {
sbpctx := Context{}
sbpctx.Command = cmd
sbpctx.History = make([]string, 10)
return &sbpctx
}

Expand All @@ -36,9 +37,15 @@ func (sbpctx *Context) StartWith(Parameter string) {
log.Fatal(err)
}
sbpctx.Parameter = Parameter
if Parameter != sbpctx.History[len(sbpctx.History)-1] {
sbpctx.History = sbpctx.History[1:]
sbpctx.History = append(sbpctx.History, Parameter)

if len(sbpctx.History) == 0 {
sbpctx.History = []string{Parameter}
}
if Parameter != sbpctx.History[0] {
sbpctx.History = append([]string{Parameter}, sbpctx.History...)
}
if len(sbpctx.History) > maxHistory {
sbpctx.History = sbpctx.History[:maxHistory]
}
}

Expand Down

0 comments on commit aab85ab

Please sign in to comment.