Skip to content

Commit

Permalink
Add function: complete_for_files
Browse files Browse the repository at this point in the history
  • Loading branch information
hymkor committed Jul 11, 2020
1 parent 7d50431 commit 9a1e128
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
23 changes: 23 additions & 0 deletions functions/builtinfunc.go
Expand Up @@ -2,6 +2,8 @@ package functions

import (
"bufio"
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -528,3 +530,24 @@ func CmdEnvDel(args []any_t) (result []any_t) {
}
return
}

func CmdCompleteForFiles(args []any_t) []any_t {
if len(args) < 1 {
return []any_t{nil, errors.New("too few arguments")}
}
if s, ok := args[0].(string); ok {
elements, err := completion.ListUpFiles(
context.TODO(),
completion.DoNotUncCompletion,
s)
if err != nil {
return []any_t{nil, err.Error()}
}
result := make([]string, len(elements))
for i := 0; i < len(elements); i++ {
result[i] = elements[i].String()
}
return []any_t{result}
}
return []any_t{nil, errors.New("invalid arguments")}
}
53 changes: 27 additions & 26 deletions functions/table.go
@@ -1,32 +1,33 @@
package functions

var Table = map[string]func([]interface{}) []interface{}{
"access": CmdAccess,
"envadd": CmdEnvAdd,
"envdel": CmdEnvDel,
"atou": CmdAtoU,
"bitand": CmdBitAnd,
"bitor": CmdBitOr,
"chdir": CmdChdir,
"commonprefix": CmdCommonPrefix,
"elevated": CmdElevated,
"fields": CmdFields,
"getenv": CmdGetEnv,
"gethistory": CmdGetHistory,
"getkey": CmdGetKey,
"getviewwidth": CmdGetViewWidth,
"getwd": CmdGetwd,
"glob": CmdGlob,
"msgbox": CmdMsgBox,
"pathjoin": CmdPathJoin,
"dirname": CmdDirName,
"resetcharwidth": CmdResetCharWidth,
"setenv": CmdSetEnv,
"setrunewidth": CmdSetRuneWidth,
"shellexecute": CmdShellExecute,
"stat": CmdStat,
"utoa": CmdUtoA,
"which": CmdWhich,
"access": CmdAccess,
"envadd": CmdEnvAdd,
"envdel": CmdEnvDel,
"atou": CmdAtoU,
"bitand": CmdBitAnd,
"bitor": CmdBitOr,
"chdir": CmdChdir,
"commonprefix": CmdCommonPrefix,
"complete_for_files": CmdCompleteForFiles,
"elevated": CmdElevated,
"fields": CmdFields,
"getenv": CmdGetEnv,
"gethistory": CmdGetHistory,
"getkey": CmdGetKey,
"getviewwidth": CmdGetViewWidth,
"getwd": CmdGetwd,
"glob": CmdGlob,
"msgbox": CmdMsgBox,
"pathjoin": CmdPathJoin,
"dirname": CmdDirName,
"resetcharwidth": CmdResetCharWidth,
"setenv": CmdSetEnv,
"setrunewidth": CmdSetRuneWidth,
"shellexecute": CmdShellExecute,
"stat": CmdStat,
"utoa": CmdUtoA,
"which": CmdWhich,
}

var Table2 = map[string]func(*Param) []interface{}{
Expand Down

0 comments on commit 9a1e128

Please sign in to comment.