forked from liuchengxu/space-vim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
192 lines (170 loc) · 4.98 KB
/
install.ps1
File metadata and controls
192 lines (170 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
if (-not (Test-Path env:HOME)) {$env:HOME = ${env:USERPROFILE}}
if (-not (Test-Path env:APP_PATH)) {$env:APP_PATH= "${env:HOME}\.space-vim"}
$DOTSPACEVIM = "${env:HOME}\.space-vim"
$APP_NAME = "space-vim"
$REPO_URI = "https://github.com/liuchengxu/space-vim.git"
$REPO_BRANCH = "master"
$VIM_PLUG_PATH = "${env:HOME}\.vim\autoload"
$VIM_PLUG_URL = "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
function Msg
{
Param(
[string]$symbol=$null,
[string]$str,
[string]$color
)
if (-not $symbol)
{
Write-Host $symbol -ForegroundColor $color -NoNewline
}
Write-Host "$($str)"
}
function Success([string]$str)
{
if ($? -eq $true)
{
Msg -symbol "[✓]" -str $str -color "Green"
}
}
function Error([string]$str)
{
msg -symbol "[✗]" -str $str -color "Red"
Write-Host "Press any key to exit ..."
$x = $host.UI.RawUI.ReadKey("")
exit
}
function Get-InstalledApps
{
if ([IntPtr]::Size -eq 4) {
$regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
}
else {
$regpath = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
}
Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString |Sort DisplayName
}
function CheckExist ([string]$app_name)
{
$result = Get-InstalledApps | where {$_.DisplayName -like $app_name}
if ($result -eq $null)
{
return ,$false
}
return ,$true
}
function MustExist ([string]$app_name)
{
$exist = $(CheckExist -app_name "$($app_name)*")
if ($exist -eq $false)
{
Error -str "You must have '$($app_name)' installed to continue"
}
}
function MklinkIf ([string]$target, [string]$source)
{
if (Test-Path $source)
{
cmd /c mklink $target $source
}
}
function Backup ([string]$backup)
{
if (Test-Path $backup)
{
msg -str "Attempting to back up your original vim configuration."
$today = Get-Date -UFormat "%Y%m%d_%s"
Rename-Item -Path $backup -NewName "$($backup).$($today)"
Success -str Your original vim configuration has been backed up.
}
}
function MakeSymlink ([string]$target, [string]$source)
{
MklinkIf -target "$($target)\.vimrc" -source "$($source)\init.vim"
Success -str "Setting up vim symlinks."
}
function SyncRepo
{
Param
(
[string]$repo_path,
[string]$repo_uri,
[string]$repo_branch,
[string]$repo_name
)
if (-not (Test-Path $repo_path))
{
Write-Host "==>" -ForegroundColor "Blue" -NoNewline
Write-Host "Trying to clone $($repo_name)"
git clone -b $repo_branch $repo_uri $repo_path
Success -str "Successfully cloned $($repo_name)."
}
else
{
Write-Host "==>" -ForegroundColor "Blue" -NoNewline
Write-Host "Trying to update $($repo_name)"
cd $repo_path
git pull origin $repo_branch
Success -str "Successfully updated $($repo_name)."
}
}
function SyncVimplug ([string]$path, [string]$url)
{
if (-not (Test-Path $path))
{
mkdir $path
(New-Object System.Net.WebClient).DownloadFile($url, $path)
}
}
function SetupVimplug
{
vim -u "${env:HOME}\.vimrc" +PlugInstall! +PlugClean +qall
Success -str "Now updating/installing plugins using vim-plug"
}
function MakeDotSpacevim
{
if (-not (Test-Path $DOTSPACEVIM))
{
$text =@"
" You can enable the existing layers in space-vim and
" exclude the partial plugins in a certain layer.
" The command Layer and Exlcude are vaild in the function Layers().
function! Layers()
" Default layers, recommended!
Layer 'fzf'
Layer 'unite'
Layer 'better-defaults'
endfunction
" Put your private plugins here.
function! UserInit()
" Space has been set as the default leader key,
" if you want to change it, uncomment and set it here.
" let g:spacevim_leader = "<\Space>"
" let g:spacevim_localleader = ','
" Install private plugins
" Plug 'extr0py/oni'
endfunction
" Put your costom configurations here, e.g., change the colorscheme.
function! UserConfig()
" If you enable airline layer and have installed the powerline fonts, set it here.
" let g:airline_powerline_fonts=1
" color desert
"@
Set-Content -Path $DOTSPACEVIM -Value $text
}
}
MustExist -app_name "Vim"
MustExist -app_name "Git"
Backup -backup "${env:HOME}\.virmc"
SyncRepo -repo_path $env:APP_PATH -repo_uri $REPO_URI -repo_branch $REPO_BRANCH -repo_name $APP_NAME
MakeSymlink -target $env:HOME -source $env:APP_PATH
SyncVimplug -path $VIM_PLUG_PATH -url $VIM_PLUG_URL
MakeDotSpacevim
SetupVimplug
Write-Host "Thanks for installing " -NoNewline
Msg -symbol $APP_NAME -str ". Enjoy!" -color "Red"
Write-Host "Press any key to exit ..."
$x = $host.UI.RawUI.ReadKey("")
exit