Import initial history from fish too

This commit is contained in:
David Dworken
2022-11-03 22:32:55 -07:00
parent c5aff4085d
commit d4ca466314
3 changed files with 23 additions and 2 deletions

View File

@@ -533,6 +533,11 @@ func ImportHistory(ctx *context.Context, shouldReadStdin bool) (int, error) {
return 0, fmt.Errorf("failed to parse zsh history: %v", err)
}
historyEntries = append(historyEntries, extraEntries...)
extraEntries, err = parseFishHistory(homedir)
if err != nil {
return 0, fmt.Errorf("failed to parse fish history: %v", err)
}
historyEntries = append(historyEntries, extraEntries...)
if shouldReadStdin {
extraEntries, err = readStdin()
if err != nil {
@@ -550,7 +555,7 @@ func ImportHistory(ctx *context.Context, shouldReadStdin bool) (int, error) {
return 0, err
}
for _, cmd := range historyEntries {
if isZshWeirdness(cmd) || isBashWeirdness(cmd) {
if isZshWeirdness(cmd) || isBashWeirdness(cmd) || strings.HasPrefix(cmd, " ") {
// Skip it
continue
}
@@ -601,6 +606,21 @@ func readStdin() ([]string, error) {
return ret, nil
}
func parseFishHistory(homedir string) ([]string, error) {
lines, err := readFileToArray(filepath.Join(homedir, ".local/share/fish/fish_history"))
if err != nil {
return nil, err
}
ret := make([]string, 0)
for _, line := range lines {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "- cmd: ") {
ret = append(ret, strings.SplitN(line, ": ", 2)[1])
}
}
return ret, nil
}
func parseBashHistory(homedir string) ([]string, error) {
return readFileToArray(filepath.Join(homedir, ".bash_history"))
}