Esempio n. 1
0
        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;
            }
            PathExtensions.CreateDirectories(file);
            var template = new ScriptLocator(_token, Environment.CurrentDirectory).GetTemplateFor(extension);
            var content  = "";

            if (template != null)
            {
                File.Copy(template, file);
            }
            else
            {
                var templates = new ScriptLocator(_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\"");
        }
Esempio n. 2
0
        private string getPath(string[] arguments)
        {
            var isGlobal = arguments.Contains("--global") || arguments.Contains("-g");
            var locator  = new ScriptLocator(_token, Environment.CurrentDirectory);

            if (isGlobal)
            {
                return(locator.GetGlobalPath());
            }
            else
            {
                return(locator.GetLocalPath());
            }
        }
Esempio n. 3
0
 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 file = Path.Combine(
         getPath(arguments),
         filename);
     if (extension != null)
         file += extension;
     if (File.Exists(file))
         return;
     PathExtensions.CreateDirectories(file);
     var template = new ScriptLocator().GetTemplateFor(extension);
     var content = "";
     if (template != null)
         File.Copy(template, file);
     else
     {
         var templates = new ScriptLocator().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("editor goto \"" + file + "|0|0\"");
 }
Esempio n. 4
0
        private void newScript(string[] args)
        {
            var language = getLanguage(args[2]);

            if (language == null)
            {
                return;
            }
            var filename = getFileName(args[3]);

            if (filename == null)
            {
                return;
            }
            var extension   = getExtension(args[3]);
            var createLocal = args.Length == 5 && args[4] == "-l";
            var path        = getLanguagePath(createLocal, language, "scripts");

            if (path == null)
            {
                return;
            }
            var file = Path.Combine(
                path,
                filename);

            if (extension != null)
            {
                file += extension;
            }
            if (File.Exists(file))
            {
                return;
            }
            PathExtensions.CreateDirectories(file);
            var template = new ScriptLocator(_token, Environment.CurrentDirectory).GetTemplateFor(extension);
            var content  = "";

            if (template != null)
            {
                File.Copy(template, file);
            }
            else
            {
                var templates = new ScriptLocator(_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\"");
        }