Skip to content

Commit

Permalink
Finish which builtin command
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryLuTW committed Sep 30, 2019
1 parent 7bee0f4 commit 12f0e15
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ func parseArgs(input string) []string {
return strings.Split(input, " ")
}

func lookCommand(cmd string) {
value := aliasTable[cmd]
if value != "" {
fmt.Printf("%s: aliased to %s\n", cmd, value)
return
}

value, err := exec.LookPath(cmd)
if err == nil {
fmt.Printf("%s: %s\n", cmd, value)
return
}

fmt.Printf("%s NOT FOUND\n", cmd)
}

func executeInput(input string) error {
input = os.ExpandEnv(input)
input = expandWildcardInCmd(input)
Expand All @@ -29,6 +45,13 @@ func executeInput(input string) error {

args := parseArgs(input)

if args[0] == "which" {
for _, cmd := range args[1:] {
lookCommand(cmd)
}
return nil
}

if args[0] == "cd" {
err := os.Chdir(args[1])
return err
Expand Down

0 comments on commit 12f0e15

Please sign in to comment.