-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd-machine-profile.ps1
51 lines (40 loc) · 1.57 KB
/
add-machine-profile.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
$ErrorActionPreference = "Stop"
$machine_name=$args[0]
if (-not $machine_name) {
write-host machine_name is required
exit 1
}
$machine_title=(Get-Culture).TextInfo.ToTitleCase($machine_name)
######################
# add profile directory
$PROFILE_DIR="$HOME\AppData\Local\Microsoft\Windows Terminal\Fragments\$machine_title"
New-Item -ItemType Directory -Force -Path $PROFILE_DIR | Out-Null
# add autostart shortcut
$WshShell = New-Object -comObject WScript.Shell
$ShortcutPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\start_$machine_name.lnk"
if (Test-Path -Path "$ShortcutPath" -PathType Leaf) {
write-host $ShortcutPath already exists
} else {
$Shortcut = $WshShell.CreateShortcut($ShortcutPath)
$Shortcut.TargetPath = "vagrant"
$Shortcut.Arguments = "up"
$Shortcut.WorkingDirectory = "$PSScriptRoot"
$Shortcut.Save()
}
######################
# read json and create the updated profile
$PROFILE_FILE="$HOME\AppData\Local\Microsoft\Windows Terminal\Fragments\$machine_title\$machine_name.json"
if (Test-Path -Path $PROFILE_FILE -PathType Leaf) {
write-host "$PROFILE_FILE is already exists, skipping to create"
exit 0
}
$iconfile="$PSScriptRoot\config\debian.png"
$guid=New-Guid
write-host $PROFILE_FILE, icon: $iconfile, guid: $guid
$json=Get-Content -Path $PSScriptRoot\config\windows-terminal.json | ConvertFrom-Json
$profile=$json.profiles[0]
$profile.guid="{$guid}"
$profile.name=$machine_title
$profile.commandline="ssh -X $machine_name"
$profile.icon=$iconfile
$json | ConvertTo-Json -Depth 4 | Out-File -encoding ASCII -FilePath $PROFILE_FILE