diff --git a/etc/soft/nvim/+plugins/pummode/autoload/pummode.vim b/etc/soft/nvim/+plugins/pummode/autoload/pummode.vim index afda8ed..814fa60 100644 --- a/etc/soft/nvim/+plugins/pummode/autoload/pummode.vim +++ b/etc/soft/nvim/+plugins/pummode/autoload/pummode.vim @@ -43,8 +43,8 @@ func! s:do_map(mode, options, remap_p, lhs, rhs) "{{{ \ '' . s:replace_options(a:options) \ a:lhs \ s:stringf('pumvisible() ? %s : %s', - \ s:eval_key(a:rhs), - \ s:eval_key(a:lhs)) + \ a:rhs, + \ a:lhs) endfunc "}}} func! s:replace_options(options) "{{{ let table = { diff --git a/etc/soft/nvim/+plugins/terraform-vim-folding/README.md b/etc/soft/nvim/+plugins/terraform-vim-folding/README.md new file mode 100644 index 0000000..8e920aa --- /dev/null +++ b/etc/soft/nvim/+plugins/terraform-vim-folding/README.md @@ -0,0 +1,15 @@ +I love using Terraform but the files contain so much stuff! This filetype plugin causes individual resources to default to being folded up onto a single line. I find it much easier to digest Terraform code this way. Maybe you will too. + +First, set up your .tf filetype in your .vimrc: + + au BufRead,BufNewFile *.tf setlocal filetype=terraform + +Create the following directory, if you don't already have it + + mkdir -p ~/.vim/after/ftplugin + +Then put terraform.vim in that directory. By default every .tf file opens already folded. If you want to change that behavior just change `foldlevel=1` (or > 1). + +Right now this folds resource, provider, module, data, output, terraform, and variable stanzas. There may be more here in the future. + +![screenshot](https://cloud.githubusercontent.com/assets/156436/12099980/ff94a0b4-b2f9-11e5-997a-4aed67f4bb51.png) diff --git a/etc/soft/nvim/+plugins/terraform-vim-folding/ftplugin/terraform.vim b/etc/soft/nvim/+plugins/terraform-vim-folding/ftplugin/terraform.vim new file mode 100644 index 0000000..9bad1eb --- /dev/null +++ b/etc/soft/nvim/+plugins/terraform-vim-folding/ftplugin/terraform.vim @@ -0,0 +1,37 @@ +function! TerraformFolds() + let thisline = getline(v:lnum) + if match(thisline, '^resource') >= 0 + return ">1" + elseif match(thisline, '^provider') >= 0 + return ">1" + elseif match(thisline, '^module') >= 0 + return ">1" + elseif match(thisline, '^variable') >= 0 + return ">1" + elseif match(thisline, '^output') >= 0 + return ">1" + elseif match(thisline, '^data') >= 0 + return ">1" + elseif match(thisline, '^locals') >= 0 + return ">1" + elseif match(thisline, '^terraform') >= 0 + return ">1" + else + return "=" + endif +endfunction +setlocal foldmethod=expr +setlocal foldexpr=TerraformFolds() +setlocal foldlevel=0 + +function! TerraformFoldText() + let foldsize = (v:foldend-v:foldstart) + return getline(v:foldstart).' ('.foldsize.' lines)' +endfunction +setlocal foldtext=TerraformFoldText() + +"inoremap za +nnoremap za +onoremap za +vnoremap zf + diff --git a/etc/soft/nvim/+plugins/vim-terraform/CHANGELOG.md b/etc/soft/nvim/+plugins/vim-terraform/CHANGELOG.md new file mode 100644 index 0000000..a7c9b56 --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/CHANGELOG.md @@ -0,0 +1,21 @@ +# vim-terraform CHANGELOG + +## Version 1.2.1 (February 5, 2015) + +- Block indentation fix (thanks imkira@github) + +## Version 1.2.0 (December 12, 2014) + +- Add Kevin Le's syntax highlighting + +## Version 1.1.0 (December 11, 2014) + +- Remove syntax highlighting; see README.md + +## Version 1.0.1 (December 10, 2014) + +- Make this work without the JSON plugin + +## Version 1.0.0 (December 10, 2014) + +- Initial release diff --git a/etc/soft/nvim/+plugins/vim-terraform/Makefile b/etc/soft/nvim/+plugins/vim-terraform/Makefile new file mode 100644 index 0000000..066558e --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/Makefile @@ -0,0 +1,16 @@ +.PHONY: test test_deps +.ONESHELL: +.DEFAULTGOAL := test +SHELL := /bin/bash +TERM := xterm +HOME := /dev/null +VIMINIT := + +test: test_deps + bash -c 'vim -Nu <( echo "set rtp+=vader.vim,.,./after | filetype plugin indent on | syntax enable") -c "silent Vader! test/*"' + +test_deps: + command -v git; \ + RETVAL=$$?; \ + if [ $$RETVAL != 0 ]; then echo "$$(tput bold)\`git\` executable was not found on the PATH. Please install \`git\`.$$(tput sgr0)"; exit 1; fi; \ + if [ ! -d vader.vim ]; then git clone https://github.com/junegunn/vader.vim.git; fi diff --git a/etc/soft/nvim/+plugins/vim-terraform/README.md b/etc/soft/nvim/+plugins/vim-terraform/README.md new file mode 100644 index 0000000..7053e2a --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/README.md @@ -0,0 +1,99 @@ +[![](https://img.shields.io/badge/Supports%20Terraform%20Version-%3E%3D0.14.0-blue.svg)](https://github.com/hashicorp/terraform/blob/v0.14.0/CHANGELOG.md) + +## Call For Maintainers + +This plugin, along with others like it, is now maintained by the +[HashiVim](http://hashivim.github.io/) organization, which is looking for +additional maintainers and contributors. See the HashiVim home page for +further information. +- - - - +## Overview: vim-terraform + +This plugin adds a `:Terraform` command that runs terraform, with tab +completion of subcommands. It also sets up `*.tf`, `*.tfvars`, `.terraformrc` +and `terraform.rc` files to be highlighted as HCL and `*.tfstate` as JSON. + +- - - - +## Installation + +With [Vim 8 packages](http://vimhelp.appspot.com/repeat.txt.html#packages): + + git clone https://github.com/hashivim/vim-terraform.git ~/.vim/pack/plugins/start/vim-terraform + +With [Pathogen](https://github.com/tpope/vim-pathogen): + + git clone https://github.com/hashivim/vim-terraform.git ~/.vim/bundle/vim-terraform + +With [Vundle](https://github.com/VundleVim/Vundle.vim), add the following to `~/.vimrc`: + + Plugin 'hashivim/vim-terraform' + + +- - - - +## Usage + +Allow vim-terraform to align settings automatically with Tabularize. + + let g:terraform_align=1 + +Allow vim-terraform to automatically fold (hide until unfolded) sections of terraform code. Defaults to 0 which is off. + + let g:terraform_fold_sections=1 + +Allow vim-terraform to automatically format `*.tf` and `*.tfvars` files with `terraform fmt`. +You can also do this manually with the `:TerraformFmt` command. + + let g:terraform_fmt_on_save=1 + +Allow vim-terraform to use a custom path for the terraform binary. Defaults to terraform (found in $PATH) + + let g:terraform_binary_path="/usr/local/Cellar/terraform/0.13.5/bin/terraform" + +- - - - +## Updating vim-terraform +Note, this is only for maintainers of the `vim-terraform` project. + +When a new version of Terraform drops, you can run the following where x.x.x is a version such as 0.11.11 + + ./update_automagic.sh x.x.x + +At this point, add the modified files to a git branch and open a pull request. + + git checkout -b "feature/update-to-terraform-$VERSION" + git add $FILE + git commit -m "Message about update" + git push + +Add another maintainer to the pull request and await confirmation. + +- - - - +## Running tests + +To run the test suite and verify functionality + + make + +- - - - +## Credits + +Syntax highlighting and indentation by Kevin Le (@bkad) based on prior work by +Larry Gilbert (@L2G). The rest originally written by Mark Cornick + and contributors listed below. Licensed under the +ISC license. + +Thanks to the following contributors: + +- michael j talarczyk (@mijit) +- Koji Nakayama (@knakayama) +- Kris (@kostecky) +- Okumura Takahiro (@hfm) +- Paul Forman (@pforman) +- Lowe Schmidt (@lsc) +- Mario Kozjak (@mkozjak) + +The `:TerraformFmt` command is adapted from +[vim-hclfmt](https://github.com/fatih/vim-hclfmt/blob/master/autoload/fmt.vim). + +This project is intended to be a safe, welcoming space for collaboration, and +contributors are expected to adhere to the [Contributor +Covenant](http://contributor-covenant.org) code of conduct. diff --git a/etc/soft/nvim/+plugins/vim-terraform/autoload/terraform.vim b/etc/soft/nvim/+plugins/vim-terraform/autoload/terraform.vim new file mode 100644 index 0000000..bb6f7de --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/autoload/terraform.vim @@ -0,0 +1,74 @@ +let s:cpo_save = &cpoptions +set cpoptions&vim + +" Ensure no conflict with arguments from the environment +let $TF_CLI_ARGS_fmt='' + +function! terraform#fmt() abort + " Save the view. + let curw = winsaveview() + + " Make a fake change so that the undo point is right. + normal! ix + normal! "_x + + " Execute `terraform fmt`, redirecting stderr to a temporary file. + let tmpfile = tempname() + let shellredir_save = &shellredir + let &shellredir = '>%s 2>'.tmpfile + silent execute '%!'.g:terraform_binary_path.' fmt -no-color -' + let &shellredir = shellredir_save + + " If there was an error, undo any changes and show stderr. + if v:shell_error != 0 + silent undo + let output = readfile(tmpfile) + echo join(output, "\n") + endif + + " Delete the temporary file, and restore the view. + call delete(tmpfile) + call winrestview(curw) +endfunction + +function! terraform#align() abort + let p = '^.*=[^>]*$' + if exists(':Tabularize') && getline('.') =~# '^.*=' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) + let column = strlen(substitute(getline('.')[0:col('.')],'[^=]','','g')) + let position = strlen(matchstr(getline('.')[0:col('.')],'.*=\s*\zs.*')) + Tabularize/=/l1 + normal! 0 + call search(repeat('[^=]*=',column).'\s\{-\}'.repeat('.',position),'ce',line('.')) + endif +endfunction + +function! terraform#commands(ArgLead, CmdLine, CursorPos) abort + let commands = [ + \ 'init', + \ 'validate', + \ 'plan', + \ 'apply', + \ 'destroy', + \ 'console', + \ 'fmt', + \ 'force-unlock', + \ 'get', + \ 'graph', + \ 'import', + \ 'login', + \ 'logout', + \ 'output', + \ 'providers', + \ 'refresh', + \ 'show', + \ 'state', + \ 'taint', + \ 'untaint', + \ 'version', + \ 'workspace' + \ ] + return join(commands, "\n") +endfunction + +let &cpoptions = s:cpo_save +unlet s:cpo_save diff --git a/etc/soft/nvim/+plugins/vim-terraform/doc/terraform.txt b/etc/soft/nvim/+plugins/vim-terraform/doc/terraform.txt new file mode 100644 index 0000000..c291c41 --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/doc/terraform.txt @@ -0,0 +1,41 @@ +*terraform.txt* basic vim/terraform integration + +Author: HashiVim +License: ISC license +Repo: https://github.com/hashivim/vim-terraform + + + Type |gO| to see the table of contents. +============================================================================== +COMMANDS *terraform-commands* + +These commands are only available if terraform is in your PATH. + + *:Terraform* +`:Terraform` [args] Invoke an arbitrary terraform command. + + *:TerraformFmt* +`:TerraformFmt` Invoke `terraform fmt` on a current buffer. + +============================================================================== +SETTINGS *terraform-settings* + +*g:terraform_align* + Allow vim-terraform to align settings automatically with Tabularize. + Default: 0 + +*g:terraform_binary_path* + Allow vim-terraform to use a custom path for the terraform binary. + Default: terraform + +*g:terraform_fmt_on_save* + Allow vim-terraform to automatically format *.tf and *.tfvars files with + terraform fmt. You can also do this manually with the `:TerraformFmt` command. + Default: 0 + +*g:terraform_fold_sections* + Allow vim-terraform to automatically fold (hide until unfolded) sections of + terraform code. + Default: 0 + + vim:tw=78:et:ft=help:norl: diff --git a/etc/soft/nvim/+plugins/vim-terraform/ftdetect/terraform.vim b/etc/soft/nvim/+plugins/vim-terraform/ftdetect/terraform.vim new file mode 100644 index 0000000..4022aae --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/ftdetect/terraform.vim @@ -0,0 +1,4 @@ +" By default, Vim associates .tf files with TinyFugue - tell it not to. +silent! autocmd! filetypedetect BufRead,BufNewFile *.tf +autocmd BufRead,BufNewFile *.tf,*.tfvars,.terraformrc,terraform.rc set filetype=terraform +autocmd BufRead,BufNewFile *.tfstate,*.tfstate.backup set filetype=json diff --git a/etc/soft/nvim/+plugins/vim-terraform/ftplugin/terraform.vim b/etc/soft/nvim/+plugins/vim-terraform/ftplugin/terraform.vim new file mode 100644 index 0000000..a59cfbf --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/ftplugin/terraform.vim @@ -0,0 +1,67 @@ +" terraform.vim - basic vim/terraform integration +" Maintainer: HashiVim + +if exists('b:did_ftplugin') || v:version < 700 || &compatible + finish +endif +let b:did_ftplugin = 1 + +let s:cpo_save = &cpoptions +set cpoptions&vim + +" j is a relatively recent addition; silence warnings when setting it. +setlocal formatoptions-=t formatoptions+=croql +silent! setlocal formatoptions+=j +let b:undo_ftplugin = 'setlocal formatoptions<' + +if !has('patch-7.4.1142') + " Include hyphens as keyword characters so that a keyword appearing as + " part of a longer name doesn't get partially highlighted. + setlocal iskeyword+=- + let b:undo_ftplugin .= ' iskeyword<' +endif + +if get(g:, 'terraform_fold_sections', 0) + setlocal foldmethod=syntax + let b:undo_ftplugin .= ' foldmethod<' +endif + +" Set the commentstring +setlocal commentstring=#%s +let b:undo_ftplugin .= ' commentstring<' + +if get(g:, 'terraform_align', 0) && exists(':Tabularize') + inoremap = =:call terraform#align()a + let b:undo_ftplugin .= '|iunmap =' +endif + +let &cpoptions = s:cpo_save +unlet s:cpo_save + +if !exists('g:terraform_binary_path') + let g:terraform_binary_path='terraform' +endif + +if !executable(g:terraform_binary_path) + finish +endif + +let s:cpo_save = &cpoptions +set cpoptions&vim + +command! -nargs=+ -complete=custom,terraform#commands -buffer Terraform + \ execute '!'.g:terraform_binary_path.' '..' -no-color' + +command! -nargs=0 -buffer TerraformFmt call terraform#fmt() +let b:undo_ftplugin .= '|delcommand Terraform|delcommand TerraformFmt' + +if get(g:, 'terraform_fmt_on_save', 0) + augroup vim.terraform.fmt + autocmd! + autocmd BufWritePre *.tf call terraform#fmt() + autocmd BufWritePre *.tfvars call terraform#fmt() + augroup END +endif + +let &cpoptions = s:cpo_save +unlet s:cpo_save diff --git a/etc/soft/nvim/+plugins/vim-terraform/indent/terraform.vim b/etc/soft/nvim/+plugins/vim-terraform/indent/terraform.vim new file mode 100644 index 0000000..b5e866d --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/indent/terraform.vim @@ -0,0 +1,64 @@ +" Only load this file if no other indent file was loaded +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +let s:cpo_save = &cpoptions +set cpoptions&vim + +setlocal nolisp +setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab +setlocal indentexpr=TerraformIndent(v:lnum) +setlocal indentkeys+=<:>,0=},0=) +let b:undo_indent = 'setlocal lisp< autoindent< shiftwidth< tabstop< softtabstop<' + \ . ' expandtab< indentexpr< indentkeys<' + +let &cpoptions = s:cpo_save +unlet s:cpo_save + +if exists('*TerraformIndent') + finish +endif + +let s:cpo_save = &cpoptions +set cpoptions&vim + +function! TerraformIndent(lnum) + " Beginning of the file should have no indent + if a:lnum == 0 + return 0 + endif + + " Usual case is to continue at the same indent as the previous non-blank line. + let prevlnum = prevnonblank(a:lnum-1) + let thisindent = indent(prevlnum) + + " If that previous line is a non-comment ending in [ { (, increase the + " indent level. + let prevline = getline(prevlnum) + if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$' + let thisindent += &shiftwidth + endif + + " If the current line ends a block, decrease the indent level. + let thisline = getline(a:lnum) + if thisline =~# '^\s*[\)}\]]' + let thisindent -= &shiftwidth + endif + + " If the previous line starts a block comment /*, increase by one + if prevline =~# '/\*' + let thisindent += 1 + endif + + " If the previous line ends a block comment */, decrease by one + if prevline =~# '\*/' + let thisindent -= 1 + endif + + return thisindent +endfunction + +let &cpoptions = s:cpo_save +unlet s:cpo_save diff --git a/etc/soft/nvim/+plugins/vim-terraform/syntax/terraform.vim b/etc/soft/nvim/+plugins/vim-terraform/syntax/terraform.vim new file mode 100644 index 0000000..0a1d2bb --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/syntax/terraform.vim @@ -0,0 +1,71 @@ +" Forked from Larry Gilbert's syntax file +" github.com/L2G/vim-syntax-terraform + +if exists('b:current_syntax') + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +" Identifiers are made up of alphanumeric characters, underscores, and +" hyphens. +if has('patch-7.4.1142') + syn iskeyword a-z,A-Z,48-57,_,- +endif + +syn case match + +" A block is introduced by a type, some number of labels - which are either +" strings or identifiers - and an opening curly brace. Match the type. +syn match terraBlockIntroduction /^\s*\zs\K\k*\ze\s\+\(\("\K\k*"\|\K\k*\)\s\+\)*{/ contains=terraBlockType +syn keyword terraBlockType contained data locals module output provider resource terraform variable + +syn keyword terraValueBool true false on off yes no + +syn keyword terraTodo contained TODO FIXME XXX BUG TF-UPGRADE-TODO +syn region terraComment start="/\*" end="\*/" contains=terraTodo,@Spell +syn region terraComment start="#" end="$" contains=terraTodo,@Spell +syn region terraComment start="//" end="$" contains=terraTodo,@Spell + +""" misc. +syn match terraValueDec "\<[0-9]\+\([kKmMgG]b\?\)\?\>" +syn match terraValueHexaDec "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>" +syn match terraBraces "[\[\]]" + +""" skip \" and \\ in strings. +syn region terraValueString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=terraStringInterp +syn region terraStringInterp matchgroup=terraBraces start=/\${/ end=/}/ contained contains=ALL +syn region terraHereDocText start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=terraStringInterp + +"" Functions. +syn match terraFunction "[a-z0-9]\+(\@=" + +""" HCL2 +syn keyword terraRepeat for in +syn keyword terraConditional if +syn keyword terraType string bool number object tuple list map set any +syn keyword terraValueNull null + +" enable block folding +syn region terraBlockBody matchgroup=terraBraces start="{" end="}" fold transparent + +hi def link terraComment Comment +hi def link terraTodo Todo +hi def link terraBraces Delimiter +hi def link terraBlockType Structure +hi def link terraValueBool Boolean +hi def link terraValueDec Number +hi def link terraValueHexaDec Number +hi def link terraValueString String +hi def link terraHereDocText String +hi def link terraFunction Function +hi def link terraRepeat Repeat +hi def link terraConditional Conditional +hi def link terraType Type +hi def link terraValueNull Constant + +let b:current_syntax = 'terraform' + +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/etc/soft/nvim/+plugins/vim-terraform/test/syntax.vader b/etc/soft/nvim/+plugins/vim-terraform/test/syntax.vader new file mode 100644 index 0000000..64102d7 --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/test/syntax.vader @@ -0,0 +1,52 @@ +Before: + silent! set filetype=terraform + +Given terraform (user maps): + resource "aws_subnet" "dmz" { + cidr_block = "${var.dmz_subnet["${count.index}"]}" # Comment + } + +Execute (syntax is good): + AssertEqual 'terraStringInterp', SyntaxOf('count.index') + + " Check it closed the string and went back to normal mode properly. + AssertEqual 'terraComment', SyntaxOf('Comment') + + +Given terraform (heredoc syntax); +provisioner "local-exec" { + command = <> private_ips.txt && \ +my_command +CMD # Comment + + tags = {} + } +} +; + +Execute (syntax is good): + AssertEqual 'terraStringInterp', SyntaxOf('aws_instance') + AssertEqual 'terraHereDocText', SyntaxOf('my_command') + + " Closing CMD is still here doc + AssertEqual 'terraHereDocText', SyntaxOf('CMD', 2) + + " block should be closed + AssertEqual 'terraComment', SyntaxOf('Comment') + + " tags should reset syntax + AssertEqual '', SyntaxOf("tags") + + +Given terraform (nested strings): + Name = "${var.environment == "staging" ? "sgn-stg-${var.application}" : "sgn-prd-${var.application}"}" # Comment + Other = "foo" + +Execute (syntax is good): + AssertEqual 'terraStringInterp', SyntaxOf('var.environment') + AssertEqual 'terraComment', SyntaxOf('Comment') + AssertEqual '', SyntaxAt(2, 1) + +Execute ("Cleanup"): + silent! unset filetype diff --git a/etc/soft/nvim/+plugins/vim-terraform/test/terraform_align.vader b/etc/soft/nvim/+plugins/vim-terraform/test/terraform_align.vader new file mode 100644 index 0000000..13f8166 --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/test/terraform_align.vader @@ -0,0 +1,25 @@ +Before: + silent! set filetype=terraform + silent! let g:terraform_align=1 + +Given ("That g:terraform_align=1"): + You should never see me! + +Execute ("File syntax is set for terraform"): + AssertEqual "terraform", &ft + +Execute ("terraform_align is enabled"): + AssertEqual 1, g:terraform_align + +Execute ("We display the correct number of spaces when pressing tab"): + AssertEqual 2, &tabstop + +Execute ("We insert the correct number of spaces when pressing tab"): + AssertEqual 2, &softtabstop + +Execute ("Number of spaces for indentation"): + AssertEqual 2, &shiftwidth + +Execute ("Cleanup"): + silent! let g:terraform_align=0 + silent! unset filetype diff --git a/etc/soft/nvim/+plugins/vim-terraform/test/terraform_fold_sections.vader b/etc/soft/nvim/+plugins/vim-terraform/test/terraform_fold_sections.vader new file mode 100644 index 0000000..9200962 --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/test/terraform_fold_sections.vader @@ -0,0 +1,16 @@ +Before: + silent! set filetype=terraform + silent! let g:terraform_fold_sections=1 + +Given ("That g:terraform_fold_sections=1"): + You should never see me! + +Execute ("File syntax is set for terraform"): + AssertEqual "terraform", &ft + +Execute ("terraform_fold_sections is enabled"): + AssertEqual 1, g:terraform_fold_sections + +Execute ("Cleanup"): + silent! let g:terraform_fold_sections=0 + silent! unset filetype diff --git a/etc/soft/nvim/+plugins/vim-terraform/update_automagic.sh b/etc/soft/nvim/+plugins/vim-terraform/update_automagic.sh new file mode 100755 index 0000000..5c79ece --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/update_automagic.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -euo pipefail + +function usage { + echo -e " + USAGE EXAMPLES: + + ./$(basename "$0") 0.8.7 + ./$(basename "$0") 0.9.2 + " +} + +if [ $# -ne 1 ]; then + usage + exit 1 +fi + +VERSION=${1} + +PLATFORM=$(uname | tr "[:upper:]" "[:lower:]") + +echo "+) Acquiring terraform-${VERSION}" +if [ ! -f "terraform_${VERSION}_${PLATFORM}_amd64.zip" ]; then + curl -O "https://releases.hashicorp.com/terraform/${VERSION}/terraform_${VERSION}_${PLATFORM}_amd64.zip" +fi + +echo "+) Extracting terraform-${VERSION}.tar.gz" +rm -f terraform +unzip "terraform_${VERSION}_${PLATFORM}_amd64.zip" + +echo "+) Running update_commands.rb" +./update_commands.rb + +echo "+) Updating the badge in the README.md" +sed -i "/img.shields.io/c\[\![](https://img.shields.io/badge/Supports%20Terraform%20Version-%3E%3D${VERSION}-blue.svg)](https://github.com/hashicorp/terraform/blob/v${VERSION}/CHANGELOG.md)" README.md + +echo "+) Cleaning up after ourselves" +rm -f "terraform_${VERSION}_${PLATFORM}_amd64.zip" +rm -f terraform +rm -rf "terraform-${VERSION}" + +git status diff --git a/etc/soft/nvim/+plugins/vim-terraform/update_commands.rb b/etc/soft/nvim/+plugins/vim-terraform/update_commands.rb new file mode 100755 index 0000000..f394e1c --- /dev/null +++ b/etc/soft/nvim/+plugins/vim-terraform/update_commands.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby + +# Use this script to update the commands auto-completed in autoload/terraform.vim. + +require 'open3' + +command_re = /^\s{2}([a-z0-9]\S*)/ +plugin_file = 'autoload/terraform.vim' + +# Create the list of commands. + +if File.file?('./terraform') + stdout, stderr, _status = Open3.capture3('./terraform -help') +else + stdout, stderr, _status = Open3.capture3('terraform -help') +end + +output = if stderr == '' + stdout.split("\n") + else + stderr.split("\n") + end +commands = output.collect do |l| + match = command_re.match(l) + " \\ '#{match[1]}'" if match +end.reject(&:nil?).join(",\n") + +# Read in the existing plugin file. +plugin = File.open(plugin_file, 'r').readlines + +# Replace the commands lines with our new list. +first = plugin.index { |l| /^ let commands = \[/.match(l) } + 1 +last = plugin.index { |l| /^ \\ \]\n/.match(l) } +plugin.slice!(first, last - first) +commands.split("\n").reverse_each do |r| + plugin.insert(first, r) +end + +# Write the plugin file back out. +File.open(plugin_file, 'w') do |f| + f.puts plugin +end