Sublime Forum

Best Plan of action

#1

I’m new to Sublime Text…using the beta version “3” currently…and only 3 days using the application. It’s definitely an amazing application.
Installed Packages thus far: Open-Include, SideBarEnhancements
So here’s where I need direction -
Insight to issue:
I have thousands of .xml files that I have to add specific header/footer syntax into each one. (Header/Footer syntax is always the same for each file.) What I would like to accomplish is automating this process even more than I already have if possible.
Steps I have taken thus far to perform this action manually:

  1. Created 2 different Snippets (1 for the Header, 1 for the Footer)
  2. Recorded a Macro that places each item accordingly into a .xml file
  3. Utilize the SideBarEnhancement and Open-Include to perform the following function
    a. keymap to launch the “side_bar_find_files_path_containing”
    b. keymap to open all highlighted files (Alt+D)
  4. Created a basic Plugin to execute the “save_all” and “close_all” Windows Commands in one swoop when the editing is done.

Here’s my current process that I’m testing against 20 .xml files

  1. Launch the "“side_bar_find_files_path_containing”
    TAB: Instant File Search
    Type to search:
  2. Enter appropriate text to locate necessary files
  3. Use a combination of keymaps to select all required files produced from the “find” action
  4. Execute the Alt+D to open all highlighted files
  5. Keymap to execute Macro
  6. Keymap to execute “Next file in stack”
  7. Repeat steps 5,6 until I’m through all the files (I realize this should be executed per a “loop” scenario)
  8. Keymap to execute the Plugin for mass “save_all” and “close_all”

I’m just curious what the best plan of action would be…meaning, is this going to require a series of multiple PLUGINS to accomplish this and then placing into a PACKAGE?
Is it possible for me to combine a number of WindowCommand and TextCommand into one PLUGIN?
I’m a pretty quick learner if I could just get some decent suggestions on where to take all of this to automate the process rather than manually executing a number of keymappings over and over and over again.

I appreciate any direction someone could offer to me. Thanks.

0 Likes

#2

I don’t know but i would just write a (PHP) script to do such a task.
With a few lines of code you could read the contents of a directory in an array.
Than do a foreach loop to open the files, add the header and footer and save them again.
Typically something you would do with a little program/script but not with an editor.

0 Likes

#3

I think I may have been to vague with what exactly the .xml files are used for.
These files are NOT for web development…they are a very stripped down format of mail messages (Archived Bloomberg Messages) from SMARSH. My goal is to add in the header and footer to each message accordingly so that I can run a Data Parser against them to compile into an .eml file for a “prettier” view essentially within my own Archive environment; hence using the “editor” Sublime Text.

PHP is currently not an option for me…however thanks for the reply.

0 Likes

#4

Sorry to reiterate what henkbb suggested, but, I feel the same on writing a script to do the job. If PHP isn’t favored you could use Python/Ruby/JS/etc…

Doing this purely via an editor just seems to be more work than scripting it out since you’re having to update thousands of files.

If you’re still wanting to go the text editor route I’d say look around sublime.wbond.net and see if there is a plugin that does something very similar to what you need, fork it, and tweak it to your needs.

0 Likes

#5

no worries…appreciate the feed back and I will start digging into it.

0 Likes

#6

It sounds like something that sed + Unix commands should be able to help with.

Does this help?
unix.stackexchange.com/questions … es-in-bash

Not sure how you’d iterate over the files, though.

Alex

0 Likes