瀏覽代碼

PlugSnapshot to use unexpanded plug home

/cc @andreicristianpetcu

plug#begin expands its path argument and converts it to the absolute
path by default. However, it makes sense to use the unexpanded form in
case of PlugSnapshot as described in
https://github.com/junegunn/vim-plug/issues/97#issuecomment-57421483

For example, for the following cases,

- call plug#begin('~/.vim/plugged')
- call plug#begin('$HOME/.vim/plugged')

PlugSnapshot will use the exact arguments, `~/.vim/plugged` or
`$HOME/.vim/plugged`, instead of the absolute paths such as
`/home/jg/.vim/plugged`.
Junegunn Choi 11 年之前
父節點
當前提交
e7704e6cb3
共有 2 個文件被更改,包括 22 次插入2 次删除
  1. 4 2
      plug.vim
  2. 18 0
      test/workflow.vader

+ 4 - 2
plug.vim

@@ -84,6 +84,7 @@ let s:loaded = get(s:, 'loaded', {})
 
 function! plug#begin(...)
   if a:0 > 0
+    let s:plug_home_org = a:1
     let home = s:path(fnamemodify(expand(a:1), ':p'))
   elseif exists('g:plug_home')
     let home = s:path(g:plug_home)
@@ -1273,13 +1274,14 @@ function! s:revert()
 endfunction
 
 function! s:snapshot(...) abort
+  let home = get(s:, 'plug_home_org', g:plug_home)
   let [type, var, header] = s:is_win ?
     \ ['dosbatch', '%PLUG_HOME%',
     \   ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '',
-    \    ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.s:esc(g:plug_home)]] :
+    \    ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.s:esc(home)]] :
     \ ['sh', '$PLUG_HOME',
     \   ['#!/bin/bash',  '# Generated by vim-plug', '# '.strftime("%c"), '',
-    \    'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(g:plug_home)]]
+    \    'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(home)]]
 
   call s:prepare()
   execute 'setf' type

+ 18 - 0
test/workflow.vader

@@ -1021,7 +1021,25 @@ Execute (PlugClean should not try to remove unmanaged plugins inside g:plug_home
   AssertExpect 'Already clean', 1
   q
 
+**********************************************************************
+Execute (PlugSnapshot):
+  call plug#begin('$TMPDIR/plugged')
+  Plug 'junegunn/vim-emoji'
+  Plug 'junegunn/seoul256.vim'
+  call plug#end()
+
+  PlugInstall
+  PlugSnapshot
+  AssertEqual '#!/bin/bash', getline(1)
+  AssertEqual '# Generated by vim-plug', getline(2)
+  AssertEqual 'vim +PlugUpdate +qa', getline(5)
+  AssertEqual 'PLUG_HOME=$TMPDIR/plugged', getline(7)
+  AssertEqual 0, stridx(getline(9), 'cd $PLUG_HOME/seoul256.vim/ && git reset --hard')
+  AssertEqual 0, stridx(getline(10), 'cd $PLUG_HOME/vim-emoji/ && git reset --hard')
+  q
+
 Execute (Cleanup):
+  silent! call system('rm -rf '.temp_plugged)
   silent! call system('rm -rf '.temp_plugged)
   silent! call rename('fzf', 'fzf-staged')
   silent! unlet g:plugs