junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
33.89k stars 1.9k forks source link

PlugSnapshot revision #360

Closed junegunn closed 8 years ago

junegunn commented 8 years ago

Currently PlugSnapshot creates an executable shell script like follows

vim -c 'let g:plug_shallow = 0 | PlugUpdate | qa'

PLUG_HOME=~/.vim/plugged

cd $PLUG_HOME/ReplaceWithRegister/ && git reset --hard 832efc2
cd $PLUG_HOME/Vim-Jinja2-Syntax/ && git reset --hard ce9edd3
cd $PLUG_HOME/dash.vim/ && git reset --hard f74a0a3
cd $PLUG_HOME/dockerfile.vim/ && git reset --hard 36fec37
...

However, it has some issues:

  1. Even though we're setting g:plug_shallow to zero, plugins that are already installed will not be "unshallowed". In order to fix it, we have to inject git fetch --unshallow to every line which will make the script much slower.
  2. A plugin may have compiled extension and usually we build it using do option, which is executed on PlugUpdate 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 of do 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.

#!/usr/bin/env vim -S

let g:plugs['ReplaceWithRegister'].commit = '832efc2'
let g:plugs['Vim-Jinja2-Syntax'].commit = 'ce9edd3'
" ...

PlugUpdate!
qa

But there are issues with making it an executable script:

(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:

#!/bin/sh

vim -c "
let g:plugs['ReplaceWithRegister'].commit = '832efc2'
let g:plugs['Vim-Jinja2-Syntax'].commit = 'ce9edd3'

PlugUpdate!
qa
"

However, I don't know if the same can be done on Windows.

starcraftman commented 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.

junegunn commented 8 years ago

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.

junegunn commented 8 years ago

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.

starcraftman commented 8 years ago

@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:

" 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.

junegunn commented 8 years ago

Thanks for the feedback, you finally convinced me to drop my obsession on making it an executable script. Let's keep it simple.

starcraftman commented 8 years ago

@junegunn No problem. :)

junegunn commented 8 years ago

Merged #361.