ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.
(expansion string, args []string)
| 80 | |
| 81 | // ExpandAlias processes argv to see if it should be rewritten according to a user's aliases. |
| 82 | func expandAlias(expansion string, args []string) ([]string, error) { |
| 83 | extraArgs := []string{} |
| 84 | for i, a := range args { |
| 85 | if !strings.Contains(expansion, "$") { |
| 86 | extraArgs = append(extraArgs, a) |
| 87 | } else { |
| 88 | expansion = strings.ReplaceAll(expansion, fmt.Sprintf("$%d", i+1), a) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | lingeringRE := regexp.MustCompile(`\$\d`) |
| 93 | if lingeringRE.MatchString(expansion) { |
| 94 | return nil, fmt.Errorf("not enough arguments for alias: %s", expansion) |
| 95 | } |
| 96 | |
| 97 | newArgs, err := shlex.Split(expansion) |
| 98 | if err != nil { |
| 99 | return nil, err |
| 100 | } |
| 101 | |
| 102 | expanded := append(newArgs, extraArgs...) |
| 103 | |
| 104 | return expanded, nil |
| 105 | } |
| 106 | |
| 107 | // ExpandShellAlias processes argv to see if it should be rewritten according to a user's aliases. |
| 108 | func expandShellAlias(expansion string, args []string, findShFunc func() (string, error)) ([]string, error) { |