Sublime Forum

Automatically add file header plugin

#1

hi, all

 this is my first time writing sublime text2 plugin, and don't know any rules writing it, please feel free to give me any suggestion.

 the plugin ZyFileheader([github.com/fjctlzy/ZyFileheader](https://github.com/fjctlzy/ZyFileheader)) is a plugin of Sublime Text2 which helps to add file header like

{
#!/usr/bin/env python
# -- coding:utf-8 --
#*********************************************************#
# @@ScriptName: a.py
# @@Author: Your name here
# @@Create Date: 2012-11-25 22:24:14
# @@Modify Date: 2012-11-25 22:24:34
# @@Function:
#*********************************************************#
}
to your new created file, and you could define the header for yourself.
The scriptName will change if your save as file(CTRL+SHIFT+S) in sublimetext.
The modify date will change each time your press CTRL+S
A new line will be append to the end of file if not exists

I hope you like it.

0 Likes

Zyfileheader support SL3 now
#2

Seems like a great idea! I no longer use Sublime Text, but it’s a great idea nonetheless, very useful for Grease Monkey scripts. :smile:

  • Eduan
0 Likes

#3

May I ask for a few feature requests?

1.) It would be nice if we could define different file_header_format templates.
Maybe with some type of scope so that they can be automatically applied to a file with a specific extension.

E.g.:

"file_header_format.xys": "/**********************************************************#\n# @@ScriptName: \n# @@Author: @@author <@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#**********************************************************/",

.xys files are script files for XYplorer (a Windows file manager) and comment blocks are created inside

/* ... */ regions.

So a normal ctrl+1 would insert that template if I’m working inside a .xys file…

2.) Can you “reorganize” your settings that should be placed inside the Preferences.sublime-settings file?
Something like this:

{ "zyfileheader": { "ignore_files": "zy_file_header.py", "default.sublime-settings", "Preferences.sublime-settings"], "file_header_format": "#*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************#", "python": "#!/usr/bin/env python\n# -*- coding:utf-8 -*-", "shell" : "#!/usr/bin/env bash", "author" : "Your name here", "email" : "Your email here" } }
Otherwise all the different settings will be resorted (alphabetically) when the Preferences.sublime-settings file get’s rewritten, which makes it hard to edit those settings afterwards.

3.) Can we get an option to not insert a template automatically when a new file is created (via ctrl+n)?

4.) It would be nice if we could redefine the time format for created and modified date (globally or for every template).
E.g. in Germany we use: DD.MM.YYYY HH:MM:SS

Regards,
Highend

0 Likes

#4

Thanks for you reply, and I will implement 2),3) and 4) first as they are easier, and 1) will be implemented later, as it’s a bit harder…

[quote=“highend”]May I ask for a few feature requests?

1.) It would be nice if we could define different file_header_format templates.
Maybe with some type of scope so that they can be automatically applied to a file with a specific extension.

E.g.:

"file_header_format.xys": "/**********************************************************#\n# @@ScriptName: \n# @@Author: @@author <@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#**********************************************************/",

.xys files are script files for XYplorer (a Windows file manager) and comment blocks are created inside

/* ... */ regions.

So a normal ctrl+1 would insert that template if I’m working inside a .xys file…

2.) Can you “reorganize” your settings that should be placed inside the Preferences.sublime-settings file?
Something like this:

{ "zyfileheader": { "ignore_files": "zy_file_header.py", "default.sublime-settings", "Preferences.sublime-settings"], "file_header_format": "#*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************#", "python": "#!/usr/bin/env python\n# -*- coding:utf-8 -*-", "shell" : "#!/usr/bin/env bash", "author" : "Your name here", "email" : "Your email here" } }
Otherwise all the different settings will be resorted (alphabetically) when the Preferences.sublime-settings file get’s rewritten, which makes it hard to edit those settings afterwards.

3.) Can we get an option to not insert a template automatically when a new file is created (via ctrl+n)?

4.) It would be nice if we could redefine the time format for created and modified date (globally or for every template).
E.g. in Germany we use: DD.MM.YYYY HH:MM:SS

Regards,
Highend[/quote]

0 Likes

#5

hi, 2), 3), and 4) features are added, you could see the feature list now.

Features
Modify Date will change each time you save(CTRL+S) the file
ScriptName will change each time you save as(CTRL+SHIFT+S) the file
CTRL + 1 could add defined header to your current file which has no header
Custom time format, using Python datetime format, please refer to
CTRL + 1 will use file ctime as @@Create Date for existed file
You could set add_on_created to false so that when file is created, the header won’t be added automatically

0 Likes

#6

Thanks a lot, all changes are working fine so far :smile: Hope we can see the scope addition anytime in the new future.
Regards,
Highend

0 Likes

#7

Multiple header formats is supported now, please check out and have a try…But add_on_created should be set to false, let me know if you have any issues.

“zy_file_header” : {
“add_on_created”: true,
“file_header_format”: “#*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************#”,
“file_header_format.php”: “/*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************/”,
“file_header_format.c”: “/*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*******************************************************/",
“python”: "#!/usr/bin/env python\n# -
- coding:utf-8 -
-”,
“shell”: “#!/usr/bin/env bash”,
“author”: “your name here”,
“email”: “your email here”,
“time_format”: “%Y-%m-%d %H:%M:%S”,
“ignore_files”:

    ".*.sublime.*",
    "README",
    ".*.sublime-settings",
    "zy_file_header.py"
]

}

0 Likes

#8

Thanks for the fast implementation.

I have one small issue.

Atm I have defined only one template:

"file_header_format.xys": "/* *********************************************************\n * @@ScriptName: \n * @@Author: @@author <@@email>\n * @@Create Date:\n * @@Modify Date: \n * @@Function:\n********************************************************* */\n\n",

When I insert it via alt+1 I get:

[code]/* *********************************************************

@@ScriptName: .Test.xys

  • @@Author: Highend
  • @@Create Date: 09.08.2012 15:56:27

@@Modify Date: 04.12.2012 11:00:53

  • @@Function:
    ********************************************************* */

[/code]

So for two lines not the defined “*” characters are inserted but “#”.

0 Likes

#9

should be fixed now.

0 Likes

#10

Confirmed, fixed. Ty!

0 Likes

#11

Is there any advantadge versus writing a header snippet?

0 Likes

#12

seems harder to implement.

0 Likes

#13

It has been done here : github.com/jeremt/sublime-header

But still need to be improved…

0 Likes

#14

[size=200]SublimeText3 is supported[/size]

0 Likes