-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpshs_history.go
48 lines (39 loc) · 971 Bytes
/
pshs_history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import(
"strings"
"bufio"
"os"
ps "github.com/bhendo/go-powershell"
"github.com/bhendo/go-powershell/backend"
)
func findHistory() []string {
historyList := make([]string, 10)
env := checkPsOrCmd()
if env == PS {
back := &backend.Local{}
shell, err := ps.New(back)
if err != nil {
panic(err)
}
defer shell.Exit()
historyPath, _, err := shell.Execute("(Get-PSReadlineOption).HistorySavePath")
if err != nil {
panic(err)
}
historyPath = strings.Replace(historyPath, "\\", "/", -1)
historyPath = strings.Replace(historyPath, "\r", "", -1)
historyPath = strings.Replace(historyPath, "\n", "", -1)
f, err := os.Open(historyPath)
if err != nil {
panic(err)
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
historyList = append(historyList, scanner.Text())
}
} else {
// TODO: create a new history file
}
return historyList
}