-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure_powershell.ps1
85 lines (66 loc) · 2.75 KB
/
configure_powershell.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
Set-PSDebug -Strict
#we need elevation for this script
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
#change default execution policy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
#install POSH GIT
Push-Location
if(![System.IO.Directory]::Exists("C:\github\dahlbyk\posh-git"))
{
git clone https://github.com/dahlbyk/posh-git.git C:\github\dahlbyk\posh-git
cd C:\github\dahlbyk\posh-git
}
else
{
cd C:\github\dahlbyk\posh-git
git pull
}
.\install.ps1
Pop-Location
#remove that 'Could not find ssh-agent' warning when starting powershell
$profilescript = [System.IO.File]::ReadAllText("C:\github\dahlbyk\posh-git\profile.example.ps1")
$profilescript = $profilescript.Replace("Start-SshAgent", "#Start-SshAgent")
$profilescript += @"
function ex(){
explorer .
}
function sub($file){
& 'C:\Program Files\Sublime Text 3\sublime_text.exe' "$file"
}
"@
[System.IO.File]::WriteAllText("C:\github\dahlbyk\posh-git\myprofile.ps1", $profilescript);
#update all profiles to load myprofile instead of the example profile
$profiledirectory = [System.IO.Path]::GetDirectoryName($PROFILE)
$profiles = Get-ChildItem $profiledirectory -Filter *.ps1
foreach($oneprofile in $profiles)
{
$profilescriptcontent = [System.IO.File]::ReadAllText($oneprofile.FullName)
$profilescriptcontent = $profilescriptcontent.Replace("C:\github\dahlbyk\posh-git\profile.example.ps1", "C:\github\dahlbyk\posh-git\myprofile.ps1")
[System.IO.File]::WriteAllText($oneprofile.FullName, $profilescriptcontent);
}
write-host "FIXED: 'Could not find ssh-agent'"
#modify powershell shortcut to start in c:\github
#based on http://stackoverflow.com/questions/484560/editing-shortcut-lnk-properties-with-powershell
function fixPoshLink($poshlink){
if(test-path $poshlink){
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($poshlink) ## Open the lnk
$shortcut.WorkingDirectory = "C:\github\"
$shortcut.Save() ## Save
Write-Host "Fixed link: $poshlink";
}
else
{
Write-Host "link not found: $poshlink";
}
}
fixPoshLink("$env:ProgramData\Microsoft\Windows\Start Menu\Programs\System Tools\Windows PowerShell.lnk");
fixPoshLink("$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk");
#load console window properties to registry
regedit /s .\console_window_settings.reg
install-module Jump.Location