Skip to content

Instantly share code, notes, and snippets.

@VonHeikemen
Last active January 23, 2022 00:48
Show Gist options
  • Save VonHeikemen/8d19904a0100f97d98a6905fcc4b3e2f to your computer and use it in GitHub Desktop.
Save VonHeikemen/8d19904a0100f97d98a6905fcc4b3e2f to your computer and use it in GitHub Desktop.
collect commit hash from vim plugins using vimscript
let s:packpath = expand('~/.local/share/nvim/site/pack/minpac')
let s:hash_dir = expand('~/.local/share/nvim/site/pack/minpac/hashes')
let s:pattern = '/{opt,start}'
function! s:save_hashes() abort
let plugin_dirs = glob(s:packpath .. s:pattern, 1, 1)
if empty(plugin_dirs)
return
endif
let hashes = []
for dir in plugin_dirs
for plug in split(glob(dir . '*'), '\n')
let githash = system('cd ' . shellescape(plug) . ' && git rev-parse HEAD')
call add(hashes, fnamemodify(plug, ':t') . ': ' . githash)
endfor
endfor
if empty(glob(s:hash_dir))
call mkdir(s:hash_dir, 'p')
end
call writefile(hashes, s:hash_dir . '/commits_' . strftime('%Y-%m-%d@%H:%M:%S') . '.txt')
endfunction
command! PackSave call s:save_hashes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment