mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-23 14:01:00 +01:00
Import initial history from fish too
This commit is contained in:
parent
c5aff4085d
commit
d4ca466314
@ -533,6 +533,11 @@ func ImportHistory(ctx *context.Context, shouldReadStdin bool) (int, error) {
|
|||||||
return 0, fmt.Errorf("failed to parse zsh history: %v", err)
|
return 0, fmt.Errorf("failed to parse zsh history: %v", err)
|
||||||
}
|
}
|
||||||
historyEntries = append(historyEntries, extraEntries...)
|
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 {
|
if shouldReadStdin {
|
||||||
extraEntries, err = readStdin()
|
extraEntries, err = readStdin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -550,7 +555,7 @@ func ImportHistory(ctx *context.Context, shouldReadStdin bool) (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
for _, cmd := range historyEntries {
|
for _, cmd := range historyEntries {
|
||||||
if isZshWeirdness(cmd) || isBashWeirdness(cmd) {
|
if isZshWeirdness(cmd) || isBashWeirdness(cmd) || strings.HasPrefix(cmd, " ") {
|
||||||
// Skip it
|
// Skip it
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -601,6 +606,21 @@ func readStdin() ([]string, error) {
|
|||||||
return ret, nil
|
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) {
|
func parseBashHistory(homedir string) ([]string, error) {
|
||||||
return readFileToArray(filepath.Join(homedir, ".bash_history"))
|
return readFileToArray(filepath.Join(homedir, ".bash_history"))
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,6 @@ func main() {
|
|||||||
fmt.Printf("Imported %v history entries from your existing shell history\n", numImported)
|
fmt.Printf("Imported %v history entries from your existing shell history\n", numImported)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "install":
|
case "install":
|
||||||
lib.CheckFatalError(lib.Install())
|
lib.CheckFatalError(lib.Install())
|
||||||
if os.Getenv("HISHTORY_TEST") == "" {
|
if os.Getenv("HISHTORY_TEST") == "" {
|
||||||
|
@ -62,6 +62,7 @@ func BackupAndRestoreWithId(t *testing.T, id string) func() {
|
|||||||
path.Join(homedir, data.HISHTORY_PATH, "config.fish"),
|
path.Join(homedir, data.HISHTORY_PATH, "config.fish"),
|
||||||
path.Join(homedir, ".bash_history"),
|
path.Join(homedir, ".bash_history"),
|
||||||
path.Join(homedir, ".zsh_history"),
|
path.Join(homedir, ".zsh_history"),
|
||||||
|
path.Join(homedir, ".local/share/fish/fish_history"),
|
||||||
}
|
}
|
||||||
for _, file := range renameFiles {
|
for _, file := range renameFiles {
|
||||||
touchFile(file)
|
touchFile(file)
|
||||||
@ -79,6 +80,7 @@ func BackupAndRestoreWithId(t *testing.T, id string) func() {
|
|||||||
configureZshrc(homedir)
|
configureZshrc(homedir)
|
||||||
touchFile(path.Join(homedir, ".bash_history"))
|
touchFile(path.Join(homedir, ".bash_history"))
|
||||||
touchFile(path.Join(homedir, ".zsh_history"))
|
touchFile(path.Join(homedir, ".zsh_history"))
|
||||||
|
touchFile(path.Join(homedir, ".local/share/fish/fish_history"))
|
||||||
return func() {
|
return func() {
|
||||||
Check(t, os.MkdirAll(path.Join(homedir, data.HISHTORY_PATH), os.ModePerm))
|
Check(t, os.MkdirAll(path.Join(homedir, data.HISHTORY_PATH), os.ModePerm))
|
||||||
for _, file := range renameFiles {
|
for _, file := range renameFiles {
|
||||||
|
Loading…
Reference in New Issue
Block a user