Skip to content

Instantly share code, notes, and snippets.

@nnutter
Last active December 4, 2017 17:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnutter/42a83f2a0479c9a53b813b3c49eff09d to your computer and use it in GitHub Desktop.
Save nnutter/42a83f2a0479c9a53b813b3c49eff09d to your computer and use it in GitHub Desktop.
Workshop: Puppet Development with Vim

Use Git to manage $HOME

Caveats

  • Untracked files won't show up if hidden. To audit, temporarily re-enable with gh status --untracked-files=normal.
  • Have to convert submodule paths in .gitmodules to relative paths.

Setup

  1. Create a script called gh and put it in your PATH,
    #!/usr/bin/env bash
    git --git-dir "$HOME/.dotfiles.git" --work-tree "$HOME" "$@"
    
  2. Optionally, setup Bash completion,
    complete -o bashdefault -o default -o nospace -F __git_wrap__git_main gh
    
  3. Initialize your home directory,
    gh init
    
  4. Hide untracked files by default,
    gh config status.showUntrackedFiles no
    
  5. Then continue to either If creating your initial repo or If setting up an existing repo.

If creating your initial repo

  1. First do Setup.
  2. Add files,
    gh add $HOME/foo
    
  3. Commit changes,
    gh commit -v
    
  4. Add remote,
    gh remote add -f origin git@github.com:foo/bar.git
    
  5. Push changes,
    gh push -u origin master
    

If setting up an existing repo

  1. First do Setup.
  2. Add the remote,
    gh remote add -f origin git@github.com:foo/bar.git
    
  3. Checkout master,
    gh checkout master
    
  4. If conflicts, review and then force checkout master,
    gh checkout -f master
    
#!/usr/bin/env bash
set -o errexit
REPO_NAME="$1"
shift
REPO_BASE_DIR="$HOME/src/bitbucket.gsc.wustl.edu"
REPO_DIR=$(echo "$REPO_BASE_DIR/$REPO_NAME" | sed 's/~//')
REPO_URL="ssh://git@bitbucket.gsc.wustl.edu:7999/${REPO_NAME}.git"
mkdir -p "$REPO_DIR"
git clone "$@" "${REPO_URL}" "$REPO_DIR" \
|| ( rmdir -p "$(dirname $REPO_DIR)" 2> /dev/null && false )
#!/usr/bin/env bash
PACKNAME="$1"
GIT_URL="$2"
set -o errexit -o nounset -o pipefail
PACKPATH=$HOME/.vim/pack
mkdir -p "${PACKPATH}/plugins/start"
gh submodule add "$GIT_URL" "${PACKPATH}/plugins/start/${PACKNAME}"
gh commit --edit --message "add ${PACKNAME} vim pack" -- "$HOME/.gitmodules" "${PACKPATH}/plugins/start/${PACKNAME}"
vim-add-plugin ale https://github.com/w0rp/ale.git \
&& cd ~/.vim/pack/plugins/start/ale \
&& git checkout v1.6.2
vim-add-plugin puppet https://github.com/rodjek/vim-puppet.git
vim-add-plugin surround https://github.com/tpope/vim-surround.git \
&& cd ~/.vim/pack/plugins/start/surround \
&& git checkout v2.1
vim-add-plugin tabular https://github.com/godlygeek/tabular.git \
&& cd ~/.vim/pack/plugins/start/tabular \
&& git checkout 1.0.0
gh commit -v ~/.vim/pack/plugins/start/{ale,puppet,surround,tabular}
set nocompatible
filetype plugin indent on
syntax enable
set list
set listchars=
augroup indentation
autocmd!
autocmd FileType * set ts=4 sw=4 sts=4 expandtab listchars=tab:▸·,trail:·,extends:▸ nowrap
autocmd FileType go set ts=4 sw=4 sts=4 noexpandtab listchars=tab:\ \ ,trail:·
autocmd FileType puppet set ts=2 sw=2 sts=2
autocmd FileType ruby set ts=2 sw=2 sts=2
autocmd FileType yaml set ts=2 sw=2 sts=2
augroup END
if has('statusline')
" http://winterdom.com/2007/06/vimstatusline
set ls=2 " Always show status line
" Status line detail:
" %f file path
" %y file type between braces (if defined)
" %([%R%M]%) read-only, modified and modifiable flags between braces
" %{'!'[&ff=='default_file_format']}
" shows a '!' if the file format is not the platform
" default
" %{'$'[!&list]} shows a '*' if in list mode
" %{'~'[&pm=='']} shows a '~' if in patchmode
" (%{synIDattr(synID(line('.'),col('.'),0),'name')})
" only for debug : display the current syntax item name
" %= right-align following items
" #%n buffer number
" %l/%L,%c%V line number, total number of lines, and column number
function SetStatusLineStyle()
if &stl == '' || &stl =~ 'synID'
let &stl="%f %y%([%R%M]%)%{'!'[&ff=='".&ff."']}%{'$'[!&list]}%{'~'[&pm=='']}%=Buffer: %n Line: %l/%L Column: %c%V "
else
let &stl="%f %y%([%R%M]%)%{'!'[&ff=='".&ff."']}%{'$'[!&list]} (%{synIDattr(synID(line('.'),col('.'),0),'name')})%=Buffer: %n Line: %l/%L Column: %c%V "
endif
endfunc
" Switch between the normal and vim-debug modes in the status line
" nnoremap _ds :call SetStatusLineStyle()<CR>
call SetStatusLineStyle()
" " Window title
" if has('title')
" set titlestring=%t%(\ [%R%M]%)
" endif
endif
set statusline+=%{ALEGetStatusLine()}
let g:ale_lint_on_enter = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 1
let g:ale_sign_column_always = 1
let g:ale_lint_delay = 750
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
bb-clone pup/puppet-modules
cd ~/src/bitbucket.gsc.wustl.edu/pup/puppet-modules
head -n 23 Gemfile
brew install rbenv
rbenv install
gem install --version 1.15.1 bundler
bundle install
puppet-lint --version
--no-class_inherits_from_params_class-check
--no-80chars-check
--no-documentation-check
--with-filename
" remove trailing whitespace
nnoremap _$ :call Preserve("%s/\\s\\+$//e")<CR>
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment