Created
May 18, 2016 16:33
-
-
Save digital-shokunin/3c099ef2e6be30af72628276e7787de0 to your computer and use it in GitHub Desktop.
vim and git development settings for Puppet
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
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$" | |
set fileencodings=ucs-bom,utf-8,latin1 | |
endif | |
set nocompatible " Use Vim defaults (much better!) | |
set bs=indent,eol,start " allow backspacing over everything in insert mode | |
"set ai " always set autoindenting on | |
"set backup " keep a backup file | |
set viminfo='20,\"50 " read/write a .viminfo file, don't store more | |
" than 50 lines of registers | |
set history=50 " keep 50 lines of command line history | |
set ruler " show the cursor position all the time | |
" Only do this part when compiled with support for autocommands | |
if has("autocmd") | |
augroup redhat | |
autocmd! | |
" In text files, always limit the width of text to 78 characters | |
" autocmd BufRead *.txt set tw=78 | |
" When editing a file, always jump to the last cursor position | |
autocmd BufReadPost * | |
\ if line("'\"") > 0 && line ("'\"") <= line("$") | | |
\ exe "normal! g'\"" | | |
\ endif | |
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks | |
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp | |
" start with spec file template | |
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec | |
augroup END | |
endif | |
if has("cscope") && filereadable("/usr/bin/cscope") | |
set csprg=/usr/bin/cscope | |
set csto=0 | |
set cst | |
set nocsverb | |
" add any database in current directory | |
if filereadable("cscope.out") | |
cs add $PWD/cscope.out | |
" else add database pointed to by environment | |
elseif $CSCOPE_DB != "" | |
cs add $CSCOPE_DB | |
endif | |
set csverb | |
endif | |
" Switch syntax highlighting on, when the terminal has colors | |
" Also switch on highlighting the last used search pattern. | |
if &t_Co > 2 || has("gui_running") | |
syntax on | |
set hlsearch | |
endif | |
filetype plugin on | |
if &term=="xterm" | |
set t_Co=8 | |
set t_Sb=[4%dm | |
set t_Sf=[3%dm | |
endif | |
" Don't wake up system with blinking cursor: | |
" http://www.linuxpowertop.org/known.php | |
let &guicursor = &guicursor . ",a:blinkon0" |
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
#! /bin/sh | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
# first move away any on-disk changes so we're actually validating | |
# what's staged to be committed and not just what's on disk. | |
# historically, we used stash here, but it turned out to be buggy. | |
patch_filename=/tmp/stash.$$ | |
git diff --exit-code --binary --ignore-submodules --no-color > $patch_filename | |
has_unstaged_changes=$? | |
if [[ $has_unstaged_changes != 0 ]]; then | |
echo "Stashing unstaged changes in $patch_filename." | |
git checkout -- . | |
fi | |
function quit { | |
# now recover diffs to get back to pre commit state if needed. | |
if [[ $has_unstaged_changes != 0 ]]; then | |
git apply $patch_filename | |
if [[ $? != 0 ]]; then | |
git checkout -- . | |
git apply $patch_filename | |
fi | |
fi | |
rm -f $patch_filename | |
exit $1 | |
} | |
# Redirect output to stderr. | |
exec 1>&2 | |
EXITCODE=0 | |
for file in `git diff-index --cached --diff-filter=ACM --name-only $against` | |
do | |
echo "Validating ${file}..." | |
case "${file##*.}" in | |
"pp") puppet parser validate ${file} | |
;; | |
"erb") /opt/puppetlabs/puppet/bin/erb -P -x -T '-' ${file} | /opt/puppetlabs/puppet/bin/ruby -c >/dev/null | |
;; | |
"yaml") /opt/puppetlabs/puppet/bin/ruby -ryaml -e "YAML.load_file '${file}'" >/dev/null | |
;; | |
esac | |
EXITCODE=$((EXITCODE + $?)) | |
done | |
if [ $EXITCODE -ne 0 ] | |
then | |
echo | |
echo "################################################################" | |
echo -e "### \033[31mPlease fix the errors above before committing your code.\033[0m ###" | |
echo "################################################################" | |
echo | |
fi | |
if [[ -s $patch_filename ]] | |
then | |
echo | |
echo "################################################################" | |
echo "### ###" | |
echo -e "### \033[31mDid you remember to git add your updated code?\033[0m ###" | |
echo "### ###" | |
echo "################################################################" | |
echo | |
fi | |
quit $EXITCODE |
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
" turn off auto adding comments on next line | |
" so you can cut and paste reliably | |
" http://vimdoc.sourceforge.net/htmldoc/change.html#fo-table | |
set fo=tcq | |
set nocompatible | |
set modeline | |
set bg=dark | |
syntax on | |
" set default comment color to cyan instead of darkblue | |
" which is not very legible on a black background | |
highlight comment ctermfg=cyan | |
set tabstop=2 | |
set expandtab | |
set softtabstop=2 | |
set shiftwidth=2 | |
highlight LiteralTabs ctermbg=darkgreen guibg=darkgreen | |
match LiteralTabs /\s\ / | |
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen | |
match ExtraWhitespace /\s\+$/ | |
" Show me a ruler | |
set ruler | |
" Set up puppet manifest and spec options | |
au BufRead,BufNewFile *.pp | |
\ set filetype=puppet | |
au BufRead,BufNewFile *_spec.rb | |
\ nmap <F8> :!rspec --color %<CR> | |
" Enable indentation matching for =>'s | |
filetype plugin indent on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment