Skip to content

Commit

Permalink
File glob expansion.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Apr 25, 2019
1 parent 9da6733 commit c431365
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions applets/shell/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"os/exec"
"path/filepath"

"github.com/udhos/conbox/common"
)
Expand Down Expand Up @@ -144,15 +145,35 @@ LOOP:
return 0
}

func execute(tab map[string]common.AppletFunc, builtins map[string]builtinFunc, params []string) (bool, int) {
func expand(params []string) []string {

var exp []string
// 1. expand env vars

// expand params into exp
var exp1 []string
for _, p := range params {
exp = append(exp, os.ExpandEnv(p))
exp1 = append(exp1, os.ExpandEnv(p))
}

// 2. expand file globs

var exp2 []string
for _, p := range exp1 {
g, errGlob := filepath.Glob(p)
if errGlob != nil {
fmt.Printf("shell: glob: %v", errGlob)
exp2 = append(exp2, p) // keep unexpanded
continue
}
exp2 = append(exp2, g...)
}

return exp2
}

func execute(tab map[string]common.AppletFunc, builtins map[string]builtinFunc, params []string) (bool, int) {

exp := expand(params)

prog := exp[0]

// 1. lookup shell built-in
Expand Down

0 comments on commit c431365

Please sign in to comment.