dscl . -read /Users/[username] UserShell defaults to /bin/bash
()
| 117 | // dscl . -read /Users/[username] UserShell |
| 118 | // defaults to /bin/bash |
| 119 | func internalMacUserShell() string { |
| 120 | osUser, err := user.Current() |
| 121 | if err != nil { |
| 122 | return DefaultShellPath |
| 123 | } |
| 124 | ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) |
| 125 | defer cancelFn() |
| 126 | userStr := "/Users/" + osUser.Username |
| 127 | out, err := exec.CommandContext(ctx, "dscl", ".", "-read", userStr, "UserShell").CombinedOutput() |
| 128 | if err != nil { |
| 129 | return DefaultShellPath |
| 130 | } |
| 131 | outStr := strings.TrimSpace(string(out)) |
| 132 | m := userShellRegexp.FindStringSubmatch(outStr) |
| 133 | if m == nil { |
| 134 | return DefaultShellPath |
| 135 | } |
| 136 | return m[1] |
| 137 | } |
| 138 | |
| 139 | func hasDirPart(dir string, part string) bool { |
| 140 | dir = filepath.Clean(dir) |
no test coverage detected