forked from egbutter/mydots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.ps1
198 lines (161 loc) · 5.45 KB
/
go.ps1
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
193
194
195
196
197
198
##############################################################################
##
## go.ps1
##
## by ericbeurre
##
##############################################################################
<#
.SYNOPSIS
Bootstrap my powershell environment
.EXAMPLE
go.ps1 vim,ps,xl
#>
Param
(
[String] $gomode="all"
)
set-executionpolicy remotesigned
$myhome = $env:userprofile # bc forcing $home to something else is a pain
$env:home = $myhome;
[Environment]::SetEnvironmentVariable("HOME", $env:home, "User");
#
# make sure the env vars are set correctly, inconsistent on win32
#
# a lot of scripts e.g., virtualenvwrapper-powershell, assume this location is available
$psmdefault = join-path $myhome "Documents\WindowsPowerShell\Modules"
if ($env:psmodulepath.split(";") -notcontains $psmdefault) {
$env:psmodulepath += ";$($psmdefault)"
}
[Environment]::SetEnvironmentVariable("psmodulepath", $env:psmodulepath, "User")
echo "cleaned up powershell psmodule default paths:"
echo $env:psmodulepath
# vim install on win32 can be a pain
#$vimpath = join-path $myhome ".vim"
#if (-not $env:vimruntime -or ($env:vimruntime.split(";") -notcontains $vimpath)) {
# $env:vimruntime += ";$($vimpath)"
#}
#[Environment]::SetEnvironmentVariable("vimruntime", $env:vimruntime, "User")
#echo "pointed vimruntime to userprofile:"
#echo $env:vimruntime
#
# linking the files using mklink for files and junction for dirs
#
function LinkFile ([string]$tolink)
{
$source = join-path $pwd $tolink;
if ($tolink -eq "_xlstart")
{
$xlappdata = "$env:appdata\Microsoft\Excel\XLSTART";
$target = $xlappdata;
} elseif ($tolink -eq "_vim") {
$target = join-path $myhome "vimfiles"
} elseif ($tolink -eq "_psprofile.ps1") {
$psprof = $profile.currentuserallhosts;
$target = $psprof;
} elseif ($tolink -like "_ps*") {
$target = join-path $psmdefault $tolink.replace("_ps", "");
} else {
$dotlink = $tolink -replace "^_", ".";
$target = join-path $myhome $dotlink;
}
if (test-path $target)
{
$bakfile = "$($target).bak";
echo "removing last .bak, copying $target to $bakfile";
if (test-path $bakfile) { rm $bakfile -recurse -force; }
copy-item -path $target -destination $bakfile -recurse -force;
if ((Get-Item $target).psiscontainer) { junction -d $target } else { rm $target -force }
}
if ((get-item $source).psiscontainer)
{
echo "directory junction $target to $source"
junction -s $target $source
} else {
echo "file junction $target to $source"
cmd /c mklink /H $target $source
}
}
# here we handle the command line gomode, if none goes to default
if ($gomode)
{
$gomode = $gomode.split(",");
echo $gomode;
} else {
$gomode = "all";
echo "All";
}
# get our targets
Switch ($gomode)
{
"vim" { $targets += ls (join-path $pwd _vim*) }
"ps" { $targets += ls (join-path $pwd _ps*) }
"xl" { $targets += ls (join-path $pwd _xl*) }
default { $targets = ls (join-path $pwd _*) }
}
# link the targets
$targets | where-object {$_.name -notlike "*bash*"} | foreach-object { linkfile $_.name }
#
# download powershell modules
#
$modules = get-module -list | ForEach-Object { $_.name }
if ($modules -notcontains "psget")
{
echo "downloading psget"
(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
}
import-module psget
install-module posh-git -destination $psmdefault -EA silentlycontinue
install-module posh-hg -destination $psmdefault -EA silentlycontinue
install-module pscx -destination $psmdefault -EA silentlycontinue
install-module find-string -destination $psmdefault -EA silentlycontinue
install-module psurl -destination $psmdefault -EA silentlycontinue
install-module poshcode -destination $psmdefault -EA silentlycontinue
if ($modules -notcontains "AWSPowerShell")
{
echo "downloading aws powershell library"
$this_msi = "C:\this.msi"
(new-object Net.WebClient).DownloadFile("http://sdk-for-net.amazonwebservices.com/latest/AWSToolsAndSDKForNet.msi", $this_msi)
msiexec /qn /i $this_msi
rm $this_msi
}
if ($modules -notcontains "Posh-SSH")
{
echo "downloading posh ssh library"
iex (New-Object Net.WebClient).DownloadString("https://gist.github.com/darkoperator/6152630/raw/c67de4f7cd780ba367cccbc2593f38d18ce6df89/instposhsshdev")
}
#BROKEN: get-poshcode cmatrix -Destination $psmdefault
# "error proxycred" https://getsatisfaction.com/poshcode/topics/error_with_get_poshcode
#
# load virtualenvwrapper-powershell else throw error
#
if ($modules -notcontains "virtualenvwrapper")
{
try {
echo "installing virtualenvwrapper to $psmdefault"
pip install virtualenvwrapper-powershell
} catch {
echo "WARNING: python and/or pip and/or virtualenvwrapper-powershell not installed"
}
}
$workonhome = join-path $myhome ".envs"
if (-not $env:workon_home -or $env:workon_home -ne $workonhome)
{
$env:workon_hom = $workonhome
[Environment]::SetEnvironmentVariable("workon_home", $workonhome, "User")
}
# make sure pyflakes is up to date
try
{
pip install pyflakes
} catch {
echo "WARNING: python and/or pip and/or pyflakes not installed, some vim plugins will not work"
}
#
# update all the submodules in .vim directory
#
git submodule update
git submodule foreach git pull origin master
git submodule foreach git submodule init
git submodule foreach git submodule update
cd $home