From e7704e6cb3309d48d43b0b243561b66d60f715af Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 1 Oct 2014 23:14:27 +0900 Subject: [PATCH] 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`. --- plug.vim | 6 ++++-- test/workflow.vader | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plug.vim b/plug.vim index c7e9e8c..7d01b65 100644 --- a/plug.vim +++ b/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 diff --git a/test/workflow.vader b/test/workflow.vader index 0ef1a95..0e46d54 100644 --- a/test/workflow.vader +++ b/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