Skip to content

Commit

Permalink
Fixed how the app find the history file.
Browse files Browse the repository at this point in the history
  • Loading branch information
grrlopes committed Jul 13, 2023
1 parent ec9e7a8 commit bb0590a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 9 additions & 2 deletions repositories/fileparse/fconnector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import (
)

func OpenHist() (*os.File, error) {
data, err := os.Open("~/.bash_history")
homedir, err := os.UserHomeDir()
if err != nil {
log.Fatal("could not load file:", err)
log.Fatal("could not find the file:", err, "\n")
os.Exit(1)
}

data, err := os.Open(homedir + "/.bash_history")
if err != nil {
log.Fatal("could not load file:", err, "\n")
os.Exit(1)
}


return data, err
}
14 changes: 10 additions & 4 deletions usecase/fhistorytotal/fhistorytotal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ func NewFHistoryTotal(frepo repositories.IFileParsedRepository, srepo repositori
}

func (e execute) Execute() int {
file, err := os.Open("~/.bash_history")
homedir, err := os.UserHomeDir()
if err != nil {
log.Println("Error to open file:", err)
log.Fatal("could not find the file:", err, "\n")
os.Exit(1)
}

defer file.Close()
file, err := os.Open(homedir + "/.bash_history")
if err != nil {
log.Println("could not load file:", err)
}

defer file.Close()

fcount := 0
prevByte := make([]byte, 1)
Expand All @@ -39,7 +45,7 @@ func (e execute) Execute() int {
_, err := file.Read(b)

if err != nil {
log.Println("Error to open file:", err)
log.Println("could not open file:", err)
}

if b[0] == '\n' && prevByte[0] != '\r' {
Expand Down

0 comments on commit bb0590a

Please sign in to comment.