public void Execute(string[] arguments) { if (arguments.Length < 1) return; var filename = getFileName(arguments[0]); if (filename == null) return; var extension = getExtension(arguments[0]); var path = getPath(arguments); if (path == null) return; var file = Path.Combine( path, filename); if (extension != null) file += extension; if (File.Exists(file)) return; Console.WriteLine("Creating " + file); PathExtensions.CreateDirectories(file); var template = new ReactiveScriptLocator(_token, Environment.CurrentDirectory).GetTemplateFor(extension); var content = ""; if (template != null) File.Copy(template, file); else { var templates = new ReactiveScriptLocator(_token, Environment.CurrentDirectory).GetTemplates().ToArray(); if (templates.Length == 0) { File.WriteAllText(file, content); if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) run("chmod", "+x \"" + file + "\""); } else { File.WriteAllText(file, ""); File.Copy(templates[0], file); } } _dispatch("command|editor goto \"" + file + "|0|0\""); }
private string getPath(string[] arguments) { var isGlobal = arguments.Contains("--global") || arguments.Contains("-g"); var locator = new ReactiveScriptLocator(_token, Environment.CurrentDirectory); if (isGlobal) return locator.GetGlobalPath(); else return locator.GetLocalPath(); }