GetShellHistory lê o arquivo de histórico do shell e retorna seu conteúdo.
()
| 78 | |
| 79 | // GetShellHistory lê o arquivo de histórico do shell e retorna seu conteúdo. |
| 80 | func GetShellHistory() (string, error) { |
| 81 | historyFile, err := GetShellHistoryFile() |
| 82 | if err != nil { |
| 83 | return "", err |
| 84 | } |
| 85 | |
| 86 | if _, err := osStat(historyFile); os.IsNotExist(err) { |
| 87 | return "", fmt.Errorf("arquivo de histórico não encontrado: %s", historyFile) |
| 88 | } |
| 89 | |
| 90 | data, err := osReadFile(historyFile) |
| 91 | if err != nil { |
| 92 | return "", fmt.Errorf("erro ao ler o arquivo de histórico: %w", err) |
| 93 | } |
| 94 | |
| 95 | shell := GetUserShell() |
| 96 | if shell == "zsh" { |
| 97 | processedData := processZshHistory(string(data)) |
| 98 | return processedData, nil |
| 99 | } |
| 100 | |
| 101 | return string(data), nil |
| 102 | } |
| 103 | |
| 104 | // processZshHistory processa o histórico do Zsh para remover metadados e retornar apenas os comandos. |
| 105 | func processZshHistory(data string) string { |