-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
150 lines (132 loc) · 5.92 KB
/
Copy pathsetup.ps1
File metadata and controls
150 lines (132 loc) · 5.92 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
param(
[switch]$InstallToFlowLauncher
)
$ErrorActionPreference = "Stop"
$PluginDir = $PSScriptRoot
$StepCount = if ($InstallToFlowLauncher) { 5 } else { 4 }
$StepNum = 0
$StartTime = Get-Date
function Write-Step {
param([string]$Text)
$script:StepNum++
Write-Host ""
Write-Host "[$script:StepNum/$StepCount] $Text" -ForegroundColor Cyan
}
function Write-OK ([string]$msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
function Write-Fail ([string]$msg) { Write-Host " [FAIL] $msg" -ForegroundColor Red }
function Write-Info ([string]$msg) { Write-Host " [INFO] $msg" -ForegroundColor White }
function Write-Warn ([string]$msg) { Write-Host " [WARN] $msg" -ForegroundColor Yellow }
# ------------------------------------------------------------------------------
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "= hz-plugin · Setup Script =" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Plugin directory: $PluginDir" -ForegroundColor DarkGray
Write-Host ""
# ------------------------------------------------------------------------------
# Step 1 – Python
# ------------------------------------------------------------------------------
Write-Step "Checking Python installation"
try {
$pyVersion = python --version 2>&1
Write-OK "Python found: $pyVersion"
}
catch {
Write-Fail "Python not found. Install Python 3.9+ from https://python.org"
Write-Info "Make sure 'Add Python to PATH' is checked during installation."
exit 1
}
# ------------------------------------------------------------------------------
# Step 2 – Install dependencies into ./lib
# ------------------------------------------------------------------------------
Write-Step "Installing dependencies into .\lib"
Write-Info "Running: pip install -r requirements.txt -t .\lib"
pip install -r "$PluginDir\requirements.txt" -t "$PluginDir\lib" --quiet
if ($LASTEXITCODE -ne 0) {
Write-Fail "pip install failed (exit code $LASTEXITCODE)."
Write-Info "Try running: pip install -r requirements.txt -t .\lib"
exit 1
}
$libItems = (Get-ChildItem "$PluginDir\lib" -Directory -ErrorAction SilentlyContinue).Count
Write-OK "Dependencies installed ($libItems top-level packages in .\lib)"
# ------------------------------------------------------------------------------
# Step 3 – Syntax check
# ------------------------------------------------------------------------------
Write-Step "Verifying main.py syntax"
try {
$pyPath = $PluginDir.Replace("\", "/")
python -c "import ast; ast.parse(open('$pyPath/main.py', encoding='utf-8').read())"
Write-OK "Syntax check passed"
}
catch {
Write-Fail "Syntax error in main.py: $_"
exit 1
}
# ------------------------------------------------------------------------------
# Step 4 – Run tests (if pytest is available)
# ------------------------------------------------------------------------------
Write-Step "Running unit tests"
if (Get-Command pytest -ErrorAction SilentlyContinue) {
Write-Info "Running: pytest tests/ -v"
pytest "$PluginDir\tests\" -v
if ($LASTEXITCODE -ne 0) {
Write-Warn "Some tests failed. The plugin may still work, but review the output above."
}
else {
Write-OK "All tests passed"
}
}
else {
Write-Warn "pytest not found — skipping tests."
Write-Info "Install with: pip install pytest"
}
# ------------------------------------------------------------------------------
# Step 5 (optional) – Copy to Flow Launcher
# ------------------------------------------------------------------------------
if ($InstallToFlowLauncher) {
Write-Step "Installing plugin to Flow Launcher"
$flUserPath = "$env:APPDATA\FlowLauncher\Plugins"
$flPluginsPath = "$env:LOCALAPPDATA\FlowLauncher\Plugins"
$target = $null
if (Test-Path $flPluginsPath) { $target = $flPluginsPath }
elseif (Test-Path $flUserPath) { $target = $flUserPath }
if ($target) {
$dest = "$target\hz-plugin"
Write-Info "Destination: $dest"
if (Test-Path $dest) {
Write-Info "Existing installation found — cleaning up…"
Remove-Item -Recurse -Force "$dest\*"
}
else {
New-Item -ItemType Directory -Path $dest -Force | Out-Null
}
Copy-Item -Recurse -Force "$PluginDir\*" -Destination $dest `
-Exclude ".git", ".gitignore", "*.zip", "*.resolved", "tests"
$fileCount = (Get-ChildItem $dest -Recurse -File).Count
Write-OK "Plugin installed to $dest ($fileCount files copied)"
Write-Info "Restart Flow Launcher (right-click tray icon -> Restart) to load the plugin."
}
else {
Write-Warn "Flow Launcher plugins directory not found."
Write-Info "Checked: $flPluginsPath"
Write-Info "Checked: $flUserPath"
Write-Warn "Please copy the plugin folder to your Flow Launcher Plugins directory manually."
}
}
# ------------------------------------------------------------------------------
# Summary
# ------------------------------------------------------------------------------
$elapsed = (Get-Date) - $StartTime
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "= Setup complete in $([math]::Round($elapsed.TotalSeconds, 1))s =" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host " Usage:" -ForegroundColor White
Write-Host " Open Flow Launcher (Alt + Space)" -ForegroundColor DarkGray
Write-Host " Type hz -> primary monitor" -ForegroundColor DarkGray
Write-Host " Type hz2 -> second monitor" -ForegroundColor DarkGray
Write-Host " Type hz3 -> third monitor (etc.)" -ForegroundColor DarkGray
Write-Host ""
# Open Instagram Profile
Start-Process "https://instagram.com/psychowhoqustionmark"