Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions internal/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Unique(intSlice []prompt.Suggest) []prompt.Suggest {
// Completer complete commands
func Completer(d prompt.Document) []prompt.Suggest {
s := []prompt.Suggest{{Text: "help", Description: "gosh"}, {Text: "exit", Description: "gosh"}, {Text: "history", Description: "gosh"}, {Text: "clearhist", Description: "gosh"}, {Text: "tree", Description: "gosh"}, {Text: "touch", Description: "gosh"}, {Text: "mkdir", Description: "gosh"}}
var gopath string = os.Getenv("GOSH_HOME")
file, _ := os.Open(gopath + "/history.txt")
var goshHome string = os.Getenv("GOSH_HOME")
file, _ := os.Open(goshHome + "/history.txt")
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.Compare(string(scanner.Text()), "") == 0 {
Expand All @@ -51,8 +51,8 @@ func Completer(d prompt.Document) []prompt.Suggest {
// GetCommandHist Get command History
func GetCommandHist() []string {
s := []string{}
var gopath string = os.Getenv("GOSH_HOME")
file, _ := os.Open(gopath + "/history.txt")
var goshHome string = os.Getenv("GOSH_HOME")
file, _ := os.Open(goshHome + "/history.txt")
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.Compare(string(scanner.Text()), "") == 0 {
Expand Down
14 changes: 7 additions & 7 deletions internal/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

// ClearHistory clears the command history
func ClearHistory() string {
var gopath string = os.Getenv("GOSH_HOME")
f, _ := os.OpenFile(gopath+"/history.txt",
var goshHome string = os.Getenv("GOSH_HOME")
f, _ := os.OpenFile(goshHome+"/history.txt",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f.Truncate(0)
fmt.Println("\033[0;32mHistory has been cleared ✔\033[0m")
Expand All @@ -21,8 +21,8 @@ func ClearHistory() string {

// History the history command
func History() {
var gopath string = os.Getenv("GOSH_HOME")
file, _ := os.Open(gopath + "/history.txt")
var goshHome string = os.Getenv("GOSH_HOME")
file, _ := os.Open(goshHome + "/history.txt")
scanner := bufio.NewScanner(file)
var num = 1
fmt.Println(" \033[0;32m# command\033[0m")
Expand All @@ -48,14 +48,14 @@ func History() {

// UpdateHistory update the command history
func UpdateHistory(command string) {
var gopath string = os.Getenv("GOSH_HOME")
f, err := os.OpenFile(gopath+"/history.txt",
var goshHome string = os.Getenv("GOSH_HOME")
f, err := os.OpenFile(goshHome+"/history.txt",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Println(err)
}
defer f.Close()
if _, err := f.WriteString("\n" + command); err != nil {
log.Println(err)
}
f.Close()
}