Skip to content

Commit

Permalink
Manipulates string in C#, removes 'awk' pipe from shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
edassis committed Jan 6, 2024
1 parent d9e89d5 commit 474f707
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ GodotEnv/addons
GodotEnv/.addons
GodotEnv/addons.json
GodotEnv/addons.jsonc
GodotEnv.sln.DotSettings.user

.idea/
10 changes: 6 additions & 4 deletions GodotEnv/src/common/clients/EnvironmentVariableClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public interface IEnvironmentVariableClient {
public class EnvironmentVariableClient :
IEnvironmentVariableClient {

public const string USER_SHELL_COMMAND_MAC = "dscl . -read /Users/$USER UserShell | awk -F/ '{ print $NF }'";
public const string USER_SHELL_COMMAND_LINUX = "getent passwd $USER | awk -F/ '{ print $NF }'";
public const string USER_SHELL_COMMAND_MAC = "dscl . -read /Users/$USER UserShell";
public const string USER_SHELL_COMMAND_LINUX = "getent passwd $USER";
public static readonly string[] SUPPORTED_UNIX_SHELLS = ["bash", "zsh"];

public IProcessRunner ProcessRunner { get; }
Expand Down Expand Up @@ -151,13 +151,15 @@ public async Task<string> GetUserDefaultShell() {
var processResult = await shell.Run(
"sh", ["-c", USER_SHELL_COMMAND_MAC]
);
return processResult.StandardOutput.TrimEnd(Environment.NewLine.ToCharArray());
var shellName = processResult.StandardOutput.TrimEnd(Environment.NewLine.ToCharArray());
return shellName.Split('/').Last();
}
case OSType.Linux: {
var processResult = await shell.Run(
"sh", ["-c", USER_SHELL_COMMAND_LINUX]
);
return processResult.StandardOutput.TrimEnd(Environment.NewLine.ToCharArray());
var shellName = processResult.StandardOutput.TrimEnd(Environment.NewLine.ToCharArray());
return shellName.Split('/').Last();
}
case OSType.Windows:
case OSType.Unknown:
Expand Down

0 comments on commit 474f707

Please sign in to comment.