Closed junegunn closed 8 years ago
@junegunn How about we just export a vimscript file whose contents is llike below. Then user can source it from vim/nvim at his convenience and should be fine on any platform.
let s:cd = (has('win32') || has('win64')) ? 'cd /d' : 'cd'
let s:plug_home = '/home/starcraftman/.vim/plugged'
function! s:shellesc(arg)
return '"'.escape(a:arg, '"').'"'
endfunction
function! s:with_cd(cmd, dir)
return printf('%s %s && %s', s:cd, s:shellesc(a:dir), a:cmd)
endfunction
PlugUpdate
call system(s:with_cd('git reset --hard 3ae9bf9', s:plug_home . '/CamelCaseMotion'))
call system(s:with_cd('git reset --hard ca0f337', s:plug_home . '/FastFold'))
This could be improved, just a thought to start with.
Since vim-plug now supports commit hashes, we no longer need to manually execute git reset
which has the downsides I mentioned above. The second issue can be resolved with an additional PlugInstall!
command at the bottom of the script, but the point is moot since we now have an easier and more direct way to restore the snapshot.
The patch creates a file like follows
#!/usr/bin/env vim -S
" Generated by vim-plug
" Wed Dec 16 21:54:31 2015
" :source this file to restore the snapshot
let g:plugs['ReplaceWithRegister'].commit = '832efc2'
let g:plugs['Vim-Jinja2-Syntax'].commit = 'ce9edd3'
let g:plugs['dash.vim'].commit = 'f74a0a3'
let g:plugs['dockerfile.vim'].commit = '36fec37'
let g:plugs['fzf'].commit = 'ac0a62e'
let g:plugs['fzf.vim'].commit = '664a88a'
PlugUpdate!
which gives
Updated. Elapsed time: 9.865503 sec.
[===========================================================]
- Finishing ... Done!
- Post-update hook for fzf ... OK
- Checking out ac0a62e of fzf ... OK
- Checking out 832efc2 of ReplaceWithRegister ... OK
- Checking out 664a88a of fzf.vim ... OK
- Checking out ce9edd3 of Vim-Jinja2-Syntax ... OK
- Checking out 36fec37 of dockerfile.vim ... OK
- Checking out f74a0a3 of dash.vim ... OK
...
Additionally, I wanted to make it an "executable vim script", so we don't break any backward compatibility for the users who assume that the output is an executable shell script, but it seems only possible on OS X where #!/usr/bin/env vim -S
is allowed.
This works on windows
vim ^
-c "let g:plugs['Vim-Jinja2-Syntax'].commit = 'ce9edd3'" ^
-c "let g:plugs['dash.vim'].commit = 'f74a0a3'" ^
-c "let g:plugs['dockerfile.vim'].commit = '36fec37'" ^
-c "let g:plugs['fzf'].commit = 'ac0a62e'" ^
-c "let g:plugs['fzf.vim'].commit = '664a88a'" ^
-c "let g:plugs['gitv'].commit = 'e10a896'" ^
-c "let g:plugs['goyo.vim'].commit = '630f5d8'" ^
-c "PlugUpdate!" ^
-c "qa"
however, I've started to prefer the pure vim script version.
@junegunn
Since vim-plug now supports commit hashes, we no longer need to manually execute git reset which has the downsides I mentioned above. The second issue can be resolved with an additional PlugInstall! command at the bottom of the script, but the point is moot since we now have an easier and more direct way to restore the snapshot.
Very true, does simplify the vimL solution considerably.
Additionally, I wanted to make it an "executable vim script", so we don't break any backward compatibility for the users who assume that the output is an executable shell script, but it seems only possible on OS X where #!/usr/bin/env vim -S is allowed.
Seems you aren't losing much compatibility since it only worked on OSX. In my opinion the pure vimscript approach sticks to the vim-plug spirit of doing the minimal thing. Additional benefits:
(n)vim +'source snap.vim'
." Generated by vim-plug
" Wed Dec 16 21:54:31 2015
" :source this file to restore the snapshot
" or execute: vim +'source snap.vim'
let g:plugs['ReplaceWithRegister'].commit = '832efc2'
let g:plugs['Vim-Jinja2-Syntax'].commit = 'ce9edd3'
let g:plugs['dash.vim'].commit = 'f74a0a3'
let g:plugs['dockerfile.vim'].commit = '36fec37'
let g:plugs['fzf'].commit = 'ac0a62e'
let g:plugs['fzf.vim'].commit = '664a88a'
PlugUpdate!
Sometimes, breaking things is for the better, I'd say this case it leads to better experience overall. Anyway, think that's my piece, up to you.
Thanks for the feedback, you finally convinced me to drop my obsession on making it an executable script. Let's keep it simple.
@junegunn No problem. :)
Merged #361.
Currently
PlugSnapshot
creates an executable shell script like followsHowever, it has some issues:
g:plug_shallow
to zero, plugins that are already installed will not be "unshallowed". In order to fix it, we have to injectgit fetch --unshallow
to every line which will make the script much slower.do
option, which is executed onPlugUpdate
in the script. But then we check out older commits in the following lines in the script and doing so can cause compatibility issues between the result ofdo
option and the new old Vimscript source.I suggest that we change
PlugSnapshot
to create an "executable Vimscript file" which installs/updates the plugin when sourced.But there are issues with making it an executable script:
#!/usr/bin/env vim -S
, is not known to work on Linux(Making it an executable is not mandatory. I think it's still reasonable that we just create a simple Vimscript file, though it will break backward compatibility.)
Alternatively, we can consider creating a shell script that looks like follows:
However, I don't know if the same can be done on Windows.