handle escaped spaces in tokens + filepaths in completions

This commit is contained in:
Aidan 2020-08-13 12:14:10 -07:00
parent 61dd498d27
commit 546e1711e5
No known key found for this signature in database
GPG key ID: 327711E983899316
2 changed files with 11 additions and 1 deletions

View file

@ -164,6 +164,15 @@ func lex(input string) *Token {
case ';': case ';':
i = matchLineEnd(i) i = matchLineEnd(i)
start_pos = i + 1 start_pos = i + 1
// this isnt to handle string escaping
// its only to make sure that escaped spaces stay in
// the same token.
case '\\':
if i != len(input) - 1 && input[i+1] == ' '{
// eat the backslash
input = input[:i] + input[i+1:]
}
} }
if needs_alloc { if needs_alloc {

View file

@ -80,7 +80,8 @@ func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string {
completions := []string{} completions := []string{}
for _, i := range compSource { for _, i := range compSource {
if strings.HasPrefix(i, tail) { if strings.HasPrefix(i, tail) {
completions = append(completions, head + i) str := strings.ReplaceAll(i, " ", "\\ ")
completions = append(completions, head + str)
} }
} }