bbash/input_parser/auto_complete_history.go
2025-01-13 15:28:58 +01:00

56 lines
860 B
Go

package input_parser
import "bbash/environment"
func AutoCompleteHistory(input string, env environment.Env) string {
inputLength := len(input)
if inputLength == 0 {
return ""
}
tabIndex = 0
// currentCommands := []string{
// "cat",
// "cd",
// "cp",
// "echo",
// "head",
// "help",
// "ls",
// "man",
// "mv",
// "pwd",
// "rm",
// "tail",
// "touch",
// }
historyWorking := ""
for _, currentHistory := range env.History[:len(env.History)-1] {
// println("currentHistory", currentHistory)
if len(currentHistory) < inputLength {
continue
}
currentCommandWithoutEnd := currentHistory[:inputLength]
if currentCommandWithoutEnd != input {
continue
}
historyWorking = currentHistory
}
if len(historyWorking) != 0 {
historyWorking = historyWorking[inputLength:]
}
return historyWorking
}