Skip to content

Repository files navigation

FileHeaderComment v2

Therefore that the author of the original project did a perfect job but doesn't continue the development of this extension, this fork was created. It's main goal is a further development to add additional features to the extension.

This extension allow you to insert timestamp, copyright or any information to your file like comment below. The extension is able to detect multiple languages to select the correct comment prefix.

/*
* Created on Tue Feb 18 2020
*
* Copyright (c) 2020 - Your Company
*/

Features

  • insert defined parameter like date, time, datetime, filename (full list can be found here)
  • insert your own parameter and template
  • detect files language to use correct comment prefix (list can be found here)
  • define multiple templates

Quick Jump

Updates

  • [1.1.1] Added PowerShell support

  • [1.1.0] Fixed filewithproject variable

  • [1.0.2] Updated install instructions

  • [1.0.1] Fixed template variable issue

  • [1.0.0] Added support for Makefile

Installation

There are three ways to install this extension:

  • VisualStudio Marketplace (or Extensiontab within VSC)
  • manual install of vsix-file from releases
  • git-clone and manual package export with vsce
$ git clone https://github.com/Zyzonix/VSC-FileHeaderComment-v2.git
$ npm install -g vsce
$ vsce package

Setup

Firstly paste the default configuration to your settings.js:

This file can be found under extension settings, keep in mind to edit the correct settings.js file in case you are using a SSH-connection or working in a WSL-window.

	"fileHeaderComment.parameter":{
"*":{
"commentbegin": "/*",
"commentprefix": " *",
"commentend": " */",
"company": "Your Company"
}
},
"fileHeaderComment.template":{
"*":[
"${commentbegin}",
"${commentprefix} Created on ${date}",
"${commentprefix}",
"${commentprefix} Copyright (c) ${year} ${company}",
"${commentend}"
]
}

Usage

By default you don't have to set anything. It will detect most programming language for appropriate comment syntax.

Execute it from Command Pallete (menu View - Command Pallete... or ctrl+shift+p) then type command below:

  1. FileHeaderComment: Insert Default Template at Cursor
  2. FileHeaderComment: Select from Available Templates

The second command will show your available templates defined in Settings

If you want to set your own parameter and template (set from menu Preferences - User Settings), you can read explanation below

Variables

You can use parameters below in your template

ParameterFunctionExample
datecurrent dateThu May 26 2022
dateeuropcurrent date (formatted for europe)26.05.2022
timecurrent time10:23:52 PM
time24hcurrent time in 24 hour format22:23:52
datetimecurrent date + timeThu May 26 2022 11:48:52 PM
datetime24hcurrent date + time in 24 hour formatThu May 26 2022 23:48:52
company"Your Company"Company
dayday of the month26
monthcurrent month05
yearcurrent year2022
hourcurrent hour (24h)14
minutecurrent minute45
secondcurrent second20
filenamefilenamefile.py
filewithpathfilename with filepathpath/to/file.py
filewithpathandprojectfilename with filepath and projectproject/path/to/file.py
projectprojectnameproject

Language list

The following languages are automatically detected

  • Swift
  • Lua
  • Perl
  • Ruby
  • Shellscript/Bash
  • Yaml
  • Makefile
  • Python
  • VB
  • Clojure
  • XML
  • HTML
  • JavaScript
  • Java
  • PowerShell

If there's a language not on the list that you wish to use: set custom prefixes under parameters, see here or request an update via opening an issue.

Extension settings

Define all custom variables/paramenters in asterisk * like

"fileHeaderComment.parameter":{
"*":{
"company": "Your Company"
"myvar1": "My Variable 1",
"myvar2": "My Variable 2"
}
}

Use your variable in template like (asterisk * will be default template)

"fileHeaderComment.template":{
"*":[
"${commentbegin}",
"${commentprefix} Created on ${date}",
"${commentprefix}",
"${commentprefix} Copyright (c) ${year} ${company}",
"${commentprefix} my variables are ${myvar1} and ${myvar2}",
"${commentend}"
]
}

You can define multiple templates, for instance template for MIT License

"fileHeaderComment.parameter":{
"*":{
"author": "Your Name"
},
"mit":{
"license_mit":[
"The MIT License (MIT)",
" Copyright (c) ${year} ${author}",
"",
" Permission is hereby granted, free of charge, to any person obtaining a copy of this software",
" and associated documentation files (the \"Software\"), to deal in the Software without restriction,",
" including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,",
" and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,",
" subject to the following conditions:",
"",
" The above copyright notice and this permission notice shall be included in all copies or substantial",
" portions of the Software.",
"",
" THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED",
" TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL",
" THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,",
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
]
}
},
"fileHeaderComment.template":{
"*":[
"${commentbegin}",
"${commentprefix} Created by ${author}",
"${commentend}"
],
"mit":[
"${commentbegin}",
"${commentprefix} Created on ${date}",
"${commentprefix}",
"${commentprefix} ${license_mit}",
"${commentend}"
]
}

You can use your mit template above by calling it through Command Pallete and choose FileHeaderComment: Select from Available Templates.

You can set also custom comment prefixes if your language is not automatically detected:

"fileHeaderComment.parameter":{
"your_language":{
"commentbegin": "#",
"commentprefix": "#",
"commentend": "#",
"author": "Your name"
}
},
"fileHeaderComment.template":{
"your_language":{
"${commentbegin}",
"${commentprefix} Created by ${author}",
"${commentend}"
}
}

Build extension from source

--> on Debian Install Nodejs (14=< required), replace 18.x with current latest version

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install nodejs
sudo npm install -g vsce

Enter location: on Linux: ~/.vscode-server/extensions/

cd VSC-FileHeaderComment-v2

Build package:

vsce package

Readme version: 1.9

About

Extension for Visual Studio Code for auto comment headers

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages