Beispiel #1
0
        public bool WriteConfig(ShellCollection shells)
        {
            var file = GetConfigFile(createIfNotExists: true);
            var text = shells.ToYaml();

            File.WriteAllText(file, text);
            return(File.Exists(file));
        }
Beispiel #2
0
        /// <summary>
        /// Gets a collection of available shells for a Windows environment
        /// </summary>
        /// <returns>A collection of available shells</returns>
        /// <remarks>
        /// Windows is tricky since it doesn't have any native way to list available shells AFAIK.
        /// To make up for it, we're just going to assume cmd and powershell are available.
        /// Then, we can check if wsl.exe is on PATH and add that as an option.
        /// </remarks>
        private ShellCollection GetWindowsShells()
        {
            var shells = new ShellCollection {
                ["cmd"]        = "cmd.exe",
                ["powershell"] = "powershell.exe"
            };

            if (Environment.GetEnvironmentVariable("PATH").Split(";").Any(p => File.Exists(Path.Combine(p, "wsl.exe"))))
            {
                shells.AddShell("bash", "wsl.exe");
            }
            return(shells);
        }