diff --git a/cmd/shs.go b/cmd/shs.go index 3413d21..3379c7c 100644 --- a/cmd/shs.go +++ b/cmd/shs.go @@ -20,7 +20,6 @@ package main import ( "os" "fmt" - "strings" "strconv" "github.com/peterh/liner" "gitlab.com/whom/shs/ast" @@ -108,8 +107,7 @@ func main() { line.SetCtrlCAborts(true) line.SetCompleter(func(line string) (c []string) { - strtoks := strings.Split(line, " ") - return util.ShellCompleter(strtoks[len(strtoks) - 1], vars, funcs) + return util.ShellCompleter(line, vars, funcs) }) var histFile *os.File diff --git a/stdlib/call.go b/stdlib/call.go index 4a1891e..27c2e12 100644 --- a/stdlib/call.go +++ b/stdlib/call.go @@ -74,9 +74,10 @@ func call(in *ast.Token, vt ast.VarTable, ft ast.FuncTable) *ast.Token { } else { cmd = exec.Command(path) } + cmd.Env = os.Environ() + cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - cmd.Stdin = os.Stdin signalChan := make(chan os.Signal, 2) signal.Notify(signalChan, sigs...) diff --git a/util/shell_complete.go b/util/shell_complete.go index 8246ff5..67e9b6c 100644 --- a/util/shell_complete.go +++ b/util/shell_complete.go @@ -19,8 +19,8 @@ package util import ( "fmt" - "io/ioutil" "strings" + "io/ioutil" "gitlab.com/whom/shs/log" "gitlab.com/whom/shs/ast" ) @@ -28,7 +28,18 @@ import ( // wrap this in a lambda that passes in the vt and ft // I suppose it could be more optimal. Fix if it bothers you func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string { - dir, path, tok := getPathBase(line) + var head, tail string + + idx := strings.LastIndex(line, " ") + if idx > 0 { + head = line[:idx+1] + tail = line[idx+1:] + } else { + head = "" + tail = line + } + + dir, path, tok := getPathBase(tail) compSource := []string{} if !path { @@ -47,7 +58,7 @@ func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string { } } else { for _, f := range fobjs { - compSource = append(compSource, f.Name()) + compSource = append(compSource, dir + "/" + f.Name()) } } @@ -58,8 +69,8 @@ func ShellCompleter(line string, vt ast.VarTable, ft ast.FuncTable) []string { completions := []string{} for _, i := range compSource { - if strings.HasPrefix(i, line) { - completions = append(completions, i) + if strings.HasPrefix(i, tail) { + completions = append(completions, head + i) } }