示例#1
0
文件: DirOptions.cs 项目: celsojr/p2u
        public static int RunDuplicateAndReturnExitCode(DirOptions options)
        {
            var localPath    = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var settingsPath = options.SettingsPath ??
                               Path.Combine(localPath, @"Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json");

            var json     = File.ReadAllText(settingsPath);
            var settings = JObject.Parse(json);

            var profiles = (JArray)settings["profiles"];

            for (int i = 0; i < profiles.Count; i++)
            {
                var startingDirectory = options.Reset
                    ? "%USERPROFILE%"
                    : options.DesiredPath ?? Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                if (profiles[i]["startingDirectory"] == null)
                {
                    profiles[i].Last.AddAfterSelf(new JProperty("startingDirectory", startingDirectory));
                }
                else
                {
                    profiles[i]["startingDirectory"] = startingDirectory;
                }
            }

            File.WriteAllText(settingsPath, settings.ToString());
            Console.WriteLine("All done! Try to hit CTRL+SHIFT+D or ALT+Click the desired profile...");

            return(0);
        }
示例#2
0
        static void Main(string[] args)
        {
            var parser       = new Parser(with => with.HelpWriter = Console.Out);
            var parserResult = parser.ParseArguments <PasteOptions, DirOptions>(args);

            parserResult
            .WithParsed <PasteOptions>(opt => PasteOptions.RunPasteAndReturnExitCode(opt))
            .WithParsed <DirOptions>(dopt => DirOptions.RunDuplicateAndReturnExitCode(dopt));
        }