Compare commits

...

3 Commits

Author SHA1 Message Date
TorchedSammy 4a4cb3409f
fix: set running to true before throwing exit hook on no input
this fixes an issue with the prompt being kind of a mess when
enter alone is pressed (and hilbish doesn't try to run anything)
2022-03-07 21:01:21 -04:00
TorchedSammy 853dfa369f
fix: add user input to history instead of hilbish expanded (closes #103) 2022-03-07 19:10:21 -04:00
TorchedSammy 738939e4c9
fix: remove duplicate binary suggestions (fixes #105) 2022-03-07 18:56:22 -04:00
3 changed files with 18 additions and 2 deletions

View File

@ -69,6 +69,8 @@ func binaryComplete(query, ctx string, fields []string) ([]string, string) {
} }
} }
completions = removeDupes(completions)
return completions, query return completions, query
} }

View File

@ -245,7 +245,7 @@ func splitInput(input string) ([]string, string) {
func cmdFinish(code uint8, cmdstr, oldInput string) { func cmdFinish(code uint8, cmdstr, oldInput string) {
// if input has space at the beginning, dont put in history // if input has space at the beginning, dont put in history
if !strings.HasPrefix(oldInput, " ") || interactive { if !strings.HasPrefix(oldInput, " ") || interactive {
handleHistory(cmdstr) handleHistory(strings.TrimSpace(oldInput))
} }
util.SetField(l, hshMod, "exitCode", lua.LNumber(code), "Exit code of last exected command") util.SetField(l, hshMod, "exitCode", lua.LNumber(code), "Exit code of last exected command")
hooks.Em.Emit("command.exit", code, cmdstr) hooks.Em.Emit("command.exit", code, cmdstr)

14
main.go
View File

@ -187,6 +187,7 @@ input:
input = strings.TrimSpace(input) input = strings.TrimSpace(input)
if len(input) == 0 { if len(input) == 0 {
running = true
hooks.Em.Emit("command.exit", 0) hooks.Em.Emit("command.exit", 0)
continue continue
} }
@ -268,3 +269,16 @@ func expandHome(path string) string {
return strings.Replace(defaultHistDir, "~", homedir, 1) return strings.Replace(defaultHistDir, "~", homedir, 1)
} }
func removeDupes(slice []string) []string {
all := make(map[string]bool)
newSlice := []string{}
for _, item := range slice {
if _, val := all[item]; !val {
all[item] = true
newSlice = append(newSlice, item)
}
}
return newSlice
}