1 Star 5 Fork 0

JanKinCai / vscodefileheader

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

VSCode FileHeader

Markeetplace Badge Install Download Size BSD License Badge

中文文档 | 英文文档

自动根据模板插入header、body内容插件,觉得不错的小伙伴们请点个赞👍~

安装

1. ctrl + shift + x
2. Search VSCodeFileHeader

or

1. ctrl + p
2. ext install jankincai.vscodefileheader

功能

  • 支持自动更新时间和作者
  • 支持自定义模板(header/body)
  • 支持内置多种语言模板
  • 支持配置文件后缀名映射模板
  • 支持过滤不需要插入header/body文件
  • 支持vscode变量
  • 支持远程同步模板(需要安装git)

命令

通过ctrl + shift + p调出vscode命令行界面,然后输入File Header, 可以看到如下命令:

  • File Header: Add header comment: 很少使用,如果ctrl+s被禁用, 才会使用该命令。
  • File Header: Crate template: 必须设置自定义模板路径,才能创建新的模板。
  • File Header: Open template: 必须处于某个文件下,才能打开对应的模板文件进行修改,通常情况下不建议直接修改默认模板文件。
  • File Header: Sync template: 必须设置git远程地址,进行模板同步(git clone xxx)。

例子

example

example

更多例子

Language

  • ActionScript
  • AppleScript
  • ASP
  • Batch
  • C
  • C#
  • C++
  • Clojire
  • CSS
  • D
  • Dart
  • Erlang
  • Go
  • Haskell
  • HTML
  • Java
  • JavaScript
  • LaTeX
  • Lisp
  • Lua
  • Matlab
  • Objective-C
  • OCaml
  • Pascal
  • Perl
  • PHP
  • Python
  • R
  • Ruby
  • Scala
  • SCSS
  • ShellScript
  • SQL
  • TypeScript
  • Vue
  • XML
  • YAML

简单配置

{
    "fileheader.author": "JanKinCai",
}

高级配置

{
    # 设置用户名(作者)
    "fileheader.author": "Your name",

    # 设置是否插入body, 默认 false
    "fileheader.body": true,

    # 设置打开文件插入内容,默认 false
    "fileheader.open": true,

    # 设置保存文件是否插入内容,默认 true
    "fileheader.save": true,

    # 设置查找头部注释最大行号,默认 10
    "fileheader.header_max_line": 10,

    # 设置时间格式, 默认 YYYY-MM-DD HH:mm:ss
    # moment.js
    "fileheader.dateformat": "YYYY-MM-DD HH:mm:ss",

    # 设置后缀映射模板
    "fileheader.file_suffix_mapping": {
        ".pyx": "Python",
        "jkc-*.h": "H"
    },

    # 设置过滤不插入模板
    "fileheader.ignore": [
        "*.txt",             
        "test.py",           
        "test/"               
    ]
}

自定义模板示例(添加邮箱)

自定义模板Header template/header/Python.tmpl:

# @Author: {{author}}
# @Date:   {{create_time}}
# @Email:  {{email}}
# @Last Modified by:   JanKinCai
# @Last Modified time: 2021-04-25 01:48:27

自定义模板Body template/body/Python.tmpl:



def main():
    print("Hello, World!")


if __name__ == "__main__":
    main()

设置自定义模板:

{
    # 模板路径(绝对路径)
    "fileheader.custom_template_path": "xxx/template/",
    "fileheader.other_config": {
        "email": "Your email",
    }
    # 设置后缀映射模板
    "fileheader.file_suffix_mapping": {
        ".py": "Python"
    },
}

高级自定义模板(完全实现自定义)

自定义模板header template/header/JKC.tmpl:

# @Name: {{name}}
# @Time: {{last_modified_time}}
# @Last Modified Author: {{name}}
# @Last Modified Time: {{last_modified_time}}

自定义模板body template/body/JKC.tmpl:


配置:

{
    "fileheader.is_header_exists": "@Name:", # 用于识别头部,避免重复插入
    # 用于识别更新最后修改作者标志
    "fileheader.update_last_modified_time_flags": "@Last Modified Time:",
    # 用于识别更新最后修改时间标志
    "fileheader.update_last_modified_author_flags": "@Last Modified Author:",
    "fileheader.other_config": {
        "name": "jankincai",
    },
    "fileheader.file_suffix_mapping": {
        ".jkc": "JKC"
    },   
}

vscode变量

https://code.visualstudio.com/docs/editor/variables-reference

自定义header template/header/Python.tmpl:

# @Author: {{author}}
# @Date:   {{create_time}}
# @Last Modified by:   {{last_modified_by}}
# @Last Modified time: {{last_modified_time}}
# {{workspaceFolder}}
# {{workspaceFolderBasename}}
# {{file}}
# {{relativeFile}}
# {{relativeFileDirname}}
# {{fileBasename}}
# {{fileBasenameNoExtension}}
# {{fileDirname}}
# {{fileExtname}}
# {{cwd}}

远程同步配置模板(需要安装git)

{
    "fileheader.custom_template_path": "xxx/template/",

    # 设置 SSH https://jdblischak.github.io/2014-09-18-chicago/novice/git/05-sshkeys.html
    # "fileheader.remote": "git@github.com:caizhengxin/fileheader-template.git"

    "fileheader.remote": "https://github.com/caizhengxin/fileheader-template.git"
}

开发者

$ git clone https://github.com/caizhengxin/vscodefileheader.git
$ code vscodefileheader
$ f5 # Enter Developer or Debug mode

发布安装包

# node_modules目录不能被.vscodeignore过滤.
$ sudo npm i vsce -g
$ vsce login jankincai
$ vsce package
$ vsce publish
Copyright (c) 2019, JanKinCai All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of vscodefileheader nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

VSCode File Header 展开 收起
TypeScript 等 3 种语言
BSD-3-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/JanKinCai/vscodefileheader.git
git@gitee.com:JanKinCai/vscodefileheader.git
JanKinCai
vscodefileheader
vscodefileheader
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891