PATHgit add .
This commit is contained in:
parent
15eeadf5d3
commit
7dc7def780
@ -17,11 +17,14 @@ import (
|
||||
"bbash/input_parser"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
var path_command []string
|
||||
var path_command map[string]string
|
||||
|
||||
func Init(env *environment.Env) {
|
||||
path_command = make(map[string]string)
|
||||
init_path(env)
|
||||
|
||||
}
|
||||
@ -48,17 +51,21 @@ func Run_command(in input_parser.Input, env *environment.Env) {
|
||||
}
|
||||
// Returns if anything was run or not
|
||||
func run_by_path(in input_parser.Input, env *environment.Env) bool {
|
||||
fmt.Print(env.Env["PATH"])
|
||||
return false
|
||||
instr, errB := path_command[in.Instruction]
|
||||
if !errB {
|
||||
return false
|
||||
}
|
||||
cmd := exec.Command(instr, strings.Fields(in.Args)...)
|
||||
output, _ := cmd.CombinedOutput()
|
||||
print(string(output))
|
||||
return true
|
||||
}
|
||||
|
||||
func init_path(env *environment.Env) {
|
||||
path := strings.Split(env.Env["PATH"], ":")
|
||||
for _, a_path := range path {
|
||||
recursive_executable_finder(a_path)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
func recursive_executable_finder(path string) {
|
||||
dir, err := os.ReadDir(path)
|
||||
@ -71,12 +78,9 @@ func recursive_executable_finder(path string) {
|
||||
continue
|
||||
}
|
||||
if !is_executable(f.Name()) {
|
||||
println("not exec")
|
||||
continue
|
||||
}
|
||||
println(f.Name())
|
||||
path_command = append(path_command, f.Name())
|
||||
|
||||
path_command[f.Name()] = filepath.Join(path, f.Name())
|
||||
}
|
||||
}
|
||||
func is_executable( name string) bool {
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func Man(in input_parser.Input, env *environment.Env) {
|
||||
switch in.Instruction {
|
||||
switch in.Args {
|
||||
case "pwd":
|
||||
fmt.Print("Output current working directory")
|
||||
case "echo":
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user