Skip to content

Commit

Permalink
home dir util
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmtmmnk committed Feb 26, 2021
1 parent 12fd848 commit f4f7931
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
10 changes: 1 addition & 9 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ilse

import (
"fmt"
"os"

"github.com/tjmtmmnk/ilse/util"
)

Expand All @@ -22,12 +19,7 @@ func NewConfig() (*Config, error) {
if err != nil {
return nil, err
}

userHomeDir, err := os.UserHomeDir()
if err != nil {
return nil, err
}
homeDir := fmt.Sprintf("%s/.ilse", userHomeDir)
homeDir := util.GetHomeDir()

return &Config{
Theme: "OneHalfDark",
Expand Down
1 change: 0 additions & 1 deletion util/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var Logger = newLogger()

func newLogger() *logger {
path := fmt.Sprintf("%s/log.txt", GetHomeDir())
log.Println(path)
file, _ := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0664)
l := log.New(file, "", log.Ldate|log.Ltime|log.Lshortfile)

Expand Down
6 changes: 6 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ func ShortFileName(fileName string) string {
}
}

func GetHomeDir() string {
userHomeDir, _ := os.UserHomeDir()
homeDir := fmt.Sprintf("%s/.ilse", userHomeDir)
return homeDir
}

// if use git, return repository
// else return current directory
func GetUserWorkDir() (string, error) {
Expand Down

0 comments on commit f4f7931

Please # to comment.