Created
November 2, 2018 14:26
-
-
Save anekos/933f1dc5b8227a2dd3f44fb7a02db8b2 to your computer and use it in GitHub Desktop.
自動で YAML に変換して書きだす Vim さん (*.x.yaml とすること)
This file contains 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
" 自動で YAML に変換して書きだす (*.x.yaml とすること) {{{ | |
function! s:yaml_to_json() | |
let l:from = expand('%') | |
let l:to = expand('%:r:r') . '.json' | |
let l:result = system('ruby -rjson -ryaml -e "puts(JSON.pretty_generate(YAML.load(ARGF.read)))" ' . shellescape(l:from) . ' > ' . shellescape(l:to)) | |
if v:shell_error | |
echoerr printf("Failed to yaml_to_json: %d\n%s", v:shell_error, l:result) | |
endif | |
endfunction | |
augroup X_YAML_TO_JSON | |
autocmd! | |
autocmd BufWritePost *.x.yaml call s:yaml_to_json() | |
augroup END | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment