parent
866a7e6a2b
commit
1eedd29546
38
complete.go
38
complete.go
@ -321,6 +321,44 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
|
s := string(acc)
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := ioutil.ReadDir(wd)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("reading directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var longest string
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
if !strings.HasPrefix(f.Name(), s) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
matches = append(matches, f.Name())
|
||||||
|
|
||||||
|
if longest != "" {
|
||||||
|
longest = matchLongest(longest, f.Name())
|
||||||
|
} else if s != "" {
|
||||||
|
longest = f.Name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if longest == "" {
|
||||||
|
longest = s
|
||||||
|
}
|
||||||
|
|
||||||
|
longestAcc = []rune(longest)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
f := tokenize(s)
|
||||||
|
9
eval.go
9
eval.go
@ -839,10 +839,15 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
case "cmd-complete":
|
case "cmd-complete":
|
||||||
var matches []string
|
var matches []string
|
||||||
if app.ui.cmdPrefix == ":" {
|
switch app.ui.cmdPrefix {
|
||||||
|
case ":":
|
||||||
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||||
} else {
|
case "/", "?":
|
||||||
|
matches, app.ui.cmdAccLeft = completeFile(app.ui.cmdAccLeft)
|
||||||
|
case "$", "%", "!", "&":
|
||||||
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||||
|
default:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user