-
-
Save valpackett/961425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" File: commonjs-package-json | |
" Author: Ash Berlin <[email protected]>, Grigory V. <[email protected]> | |
" Last Change: 8-May-2011. | |
" Version: 2.0 | |
" Usage: | |
" | |
" Use by placing something like the following in your .vimrc: | |
" | |
" let g:maintainer='{ "name": "Ash Berlin", "web": "http://ashberlin.com" }' | |
" | |
" and then save this file to ~/.vim/plugins/commonjs-package-json.vim: | |
" | |
" mkdir -p ~/.vim/plugin | |
" curl -q#L http://gist.github.com/gists/961425/download | tar xz -C ~/.vim/plugin --strip 1 | |
" | |
" or install as a submodule with pathogen | |
" | |
" git submodule add git://gist.github.com/961425.git bundle/commonjs-package-json/plugin | |
function! CommonJSPackageJsonTemplate() | |
let l:module_name=expand('%:p:h:t') | |
if !exists('g:maintainer') | |
echoerr "PackageJsonTemplate: g:maintainer needs to be set" | |
return | |
endif | |
call append(0, [ | |
\'{', | |
\' "name": "' . l:module_name . '",', | |
\' "description": "",', | |
\' "version": "0.1.0",', | |
\' "keywords": [""],', | |
\' "maintainers": [', | |
\' ' . g:maintainer, | |
\' ],', | |
\' "contributors": [', | |
\' ' . g:maintainer, | |
\' ],', | |
\' "engines": {', | |
\' "node": ">=0.4.0"', | |
\' },', | |
\ ] ) | |
" g:github_user is used by gist.vim, so lets reuse that. | |
if (exists('g:github_user') || executable('git')) | |
if !exists('g:github_user') | |
let g:github_user = substitute(system('git config --global github.user'), "\n", '', '') | |
endif | |
call append(line('$')-1, [ | |
\' "repository": {', | |
\' "type": "git",', | |
\' "url": "git://github.com/' . g:github_user . '/' . l:module_name . '.git"', | |
\' },', | |
\' "bugs": {', | |
\' "email": "",', | |
\' "url": "https://github.com/' . g:github_user . '/' . l:module_name . '/issues"', | |
\' },', | |
\' "licenses": [', | |
\' "type": "MIT",', | |
\' "url": "https://github.com/' . g:github_user . '/' . l:module_name . '/raw/master/LICENSE"', | |
\' ],', | |
\' "dependencies": {', | |
\' }', | |
\ ] ) | |
endif | |
call append(line('$')-1, [ '}' ] ) | |
" And remove the empty line at the end | |
normal dd | |
endfunction | |
if !exists("s:autocommands_loaded") | |
let s:autocommands_loaded = 1 | |
autocmd BufNewFile package.json :call CommonJSPackageJsonTemplate() | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment