Skip to content

Commit 4d4a634

Browse files
committed
fix: cross-platform temp dir and clipboard
- Replace $env:TEMP with [System.IO.Path]::GetTempPath() across all 47 affected files in profile.d/ — $env:TEMP is unset on Linux (uses $TMPDIR or /tmp); GetTempPath() returns the correct OS temp dir on Windows, Linux, and macOS without any platform branching - clipboard.ps1: replace Windows-only 'clip' copy fallback and broken 'cmd /c paste' paste fallback with full cross-platform dispatch: copy: Set-Clipboard → wl-copy (Wayland) → xclip → xsel → clip paste: Get-Clipboard → wl-paste (Wayland) → xclip -out → xsel -out → pbpaste Proper warnings emitted when no tool is available on the platform
1 parent 1f467de commit 4d4a634

48 files changed

Lines changed: 208 additions & 146 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

profile.d/3d-cad.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ try {
504504
}
505505

506506
# Create temporary Python script for Blender
507-
$tempScript = Join-Path $env:TEMP "blender_convert_$(New-Guid).py"
507+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "blender_convert_$(New-Guid).py"
508508
$scriptContent = @"
509509
import bpy
510510
import sys

profile.d/clipboard.ps1

Lines changed: 75 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,60 @@
11
# ===============================================
22
# clipboard.ps1
3-
# Clipboard helpers (cross-platform via pwsh)
3+
# Clipboard helpers (cross-platform)
44
# ===============================================
5-
6-
# Copy text to clipboard (uses Set-Clipboard when available)
75
# Tier: essential
86
# Dependencies: bootstrap, env
7+
98
if (-not (Test-Path Function:Copy-ToClipboard -ErrorAction SilentlyContinue)) {
109
<#
1110
.SYNOPSIS
1211
Copies input to the clipboard.
1312
1413
.DESCRIPTION
15-
Copies text or objects to the clipboard. Uses Set-Clipboard if available,
16-
otherwise falls back to the 'clip' command.
14+
Copies text or objects to the clipboard. Uses Set-Clipboard on Windows/pwsh,
15+
wl-copy (Wayland), xclip/xsel (X11), or pbcopy (macOS) as available.
16+
17+
.PARAMETER InputObject
18+
The object(s) to copy. Accepts pipeline input.
19+
20+
.EXAMPLE
21+
"hello" | Copy-ToClipboard
22+
23+
.EXAMPLE
24+
Get-Content file.txt | Copy-ToClipboard
1725
#>
1826
function Copy-ToClipboard {
19-
[CmdletBinding()] param([Parameter(ValueFromPipeline = $true)] $input)
27+
[CmdletBinding()]
28+
param([Parameter(ValueFromPipeline = $true)] $InputObject)
2029
process {
2130
try {
22-
# Use Test-HasCommand which handles caching and fallback internally
23-
if (Test-CachedCommand Set-Clipboard) { $input | Set-Clipboard } else { $input | Out-String | clip }
31+
if (Test-CachedCommand Set-Clipboard) {
32+
$InputObject | Set-Clipboard
33+
}
34+
elseif ($IsLinux) {
35+
$text = $InputObject | Out-String
36+
if (Test-CachedCommand wl-copy) {
37+
$text | wl-copy
38+
}
39+
elseif (Test-CachedCommand xclip) {
40+
$text | xclip -selection clipboard
41+
}
42+
elseif (Test-CachedCommand xsel) {
43+
$text | xsel --clipboard --input
44+
}
45+
else {
46+
Write-Warning "No clipboard tool found. Install wl-clipboard (Wayland) or xclip/xsel (X11)."
47+
}
48+
}
49+
elseif ($IsMacOS -and (Test-CachedCommand pbcopy)) {
50+
$InputObject | Out-String | pbcopy
51+
}
52+
elseif (Test-CachedCommand clip) {
53+
$InputObject | Out-String | clip
54+
}
55+
else {
56+
Write-Warning "No clipboard tool available on this platform."
57+
}
2458
}
2559
catch {
2660
Write-Warning "Failed to copy to clipboard: $_"
@@ -30,20 +64,48 @@ if (-not (Test-Path Function:Copy-ToClipboard -ErrorAction SilentlyContinue)) {
3064
Set-AgentModeAlias -Name 'cb' -Target 'Copy-ToClipboard'
3165
}
3266

33-
# Paste from clipboard
3467
if (-not (Test-Path Function:Get-FromClipboard -ErrorAction SilentlyContinue)) {
3568
<#
3669
.SYNOPSIS
3770
Pastes content from the clipboard.
3871
3972
.DESCRIPTION
40-
Retrieves content from the clipboard. Uses Get-Clipboard if available,
41-
otherwise falls back to the 'paste' command.
73+
Retrieves content from the clipboard. Uses Get-Clipboard on Windows/pwsh,
74+
wl-paste (Wayland), xclip/xsel (X11), or pbpaste (macOS) as available.
75+
76+
.EXAMPLE
77+
Get-FromClipboard
78+
79+
.OUTPUTS
80+
System.String
4281
#>
4382
function Get-FromClipboard {
4483
try {
45-
# Use Test-CachedCommand which handles caching and fallback internally
46-
if (Test-CachedCommand Get-Clipboard) { Get-Clipboard } else { cmd /c paste }
84+
if (Test-CachedCommand Get-Clipboard) {
85+
Get-Clipboard
86+
}
87+
elseif ($IsLinux) {
88+
if (Test-CachedCommand wl-paste) {
89+
wl-paste
90+
}
91+
elseif (Test-CachedCommand xclip) {
92+
xclip -selection clipboard -out
93+
}
94+
elseif (Test-CachedCommand xsel) {
95+
xsel --clipboard --output
96+
}
97+
else {
98+
Write-Warning "No clipboard tool found. Install wl-clipboard (Wayland) or xclip/xsel (X11)."
99+
$null
100+
}
101+
}
102+
elseif ($IsMacOS -and (Test-CachedCommand pbpaste)) {
103+
pbpaste
104+
}
105+
else {
106+
Write-Warning "No clipboard tool available on this platform."
107+
$null
108+
}
47109
}
48110
catch {
49111
Write-Warning "Failed to paste from clipboard: $_"

profile.d/conversion-modules/data/binary/binary-direct.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ try {
181181
process.exit(1);
182182
}
183183
"@
184-
$tempScript = Join-Path $env:TEMP "bson-to-msgpack-$(Get-Random).js"
184+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "bson-to-msgpack-$(Get-Random).js"
185185
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
186186
try {
187187
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath
@@ -227,7 +227,7 @@ try {
227227
process.exit(1);
228228
}
229229
"@
230-
$tempScript = Join-Path $env:TEMP "msgpack-to-bson-$(Get-Random).js"
230+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "msgpack-to-bson-$(Get-Random).js"
231231
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
232232
try {
233233
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath
@@ -274,7 +274,7 @@ try {
274274
process.exit(1);
275275
}
276276
"@
277-
$tempScript = Join-Path $env:TEMP "bson-to-cbor-$(Get-Random).js"
277+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "bson-to-cbor-$(Get-Random).js"
278278
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
279279
try {
280280
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath
@@ -319,7 +319,7 @@ try {
319319
process.exit(1);
320320
}
321321
"@
322-
$tempScript = Join-Path $env:TEMP "cbor-to-bson-$(Get-Random).js"
322+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "cbor-to-bson-$(Get-Random).js"
323323
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
324324
try {
325325
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath
@@ -362,7 +362,7 @@ try {
362362
process.exit(1);
363363
}
364364
"@
365-
$tempScript = Join-Path $env:TEMP "msgpack-to-cbor-$(Get-Random).js"
365+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "msgpack-to-cbor-$(Get-Random).js"
366366
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
367367
try {
368368
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath
@@ -405,7 +405,7 @@ try {
405405
process.exit(1);
406406
}
407407
"@
408-
$tempScript = Join-Path $env:TEMP "cbor-to-msgpack-$(Get-Random).js"
408+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "cbor-to-msgpack-$(Get-Random).js"
409409
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
410410
try {
411411
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath

profile.d/conversion-modules/data/binary/binary-protocol-capnp.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ try {
7676
process.exit(1);
7777
}
7878
"@
79-
$tempScript = Join-Path $env:TEMP "capnp-encode-$(Get-Random).js"
79+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "capnp-encode-$(Get-Random).js"
8080
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
8181
try {
8282
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath
@@ -134,7 +134,7 @@ try {
134134
process.exit(1);
135135
}
136136
"@
137-
$tempScript = Join-Path $env:TEMP "capnp-decode-$(Get-Random).js"
137+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "capnp-decode-$(Get-Random).js"
138138
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
139139
try {
140140
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath

profile.d/conversion-modules/data/binary/binary-protocol-delta.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ except Exception as e:
8080
print(f'Error: {str(e)}', file=sys.stderr)
8181
sys.exit(1)
8282
"@
83-
$tempScript = Join-Path $env:TEMP "delta-to-json-$(Get-Random).py"
83+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "delta-to-json-$(Get-Random).py"
8484
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
8585
try {
8686
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -164,7 +164,7 @@ except Exception as e:
164164
print(f'Error: {str(e)}', file=sys.stderr)
165165
sys.exit(1)
166166
"@
167-
$tempScript = Join-Path $env:TEMP "json-to-delta-$(Get-Random).py"
167+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "json-to-delta-$(Get-Random).py"
168168
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
169169
try {
170170
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -217,7 +217,7 @@ except Exception as e:
217217
print(f'Error: {str(e)}', file=sys.stderr)
218218
sys.exit(1)
219219
"@
220-
$tempScript = Join-Path $env:TEMP "delta-to-parquet-$(Get-Random).py"
220+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "delta-to-parquet-$(Get-Random).py"
221221
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
222222
try {
223223
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1

profile.d/conversion-modules/data/binary/binary-protocol-iceberg.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ except Exception as e:
6868
print(f'Error: {str(e)}', file=sys.stderr)
6969
sys.exit(1)
7070
"@
71-
$tempScript = Join-Path $env:TEMP "iceberg-to-json-$(Get-Random).py"
71+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "iceberg-to-json-$(Get-Random).py"
7272
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
7373
try {
7474
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -117,7 +117,7 @@ except Exception as e:
117117
print(f'Error: {str(e)}', file=sys.stderr)
118118
sys.exit(1)
119119
"@
120-
$tempScript = Join-Path $env:TEMP "json-to-iceberg-$(Get-Random).py"
120+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "json-to-iceberg-$(Get-Random).py"
121121
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
122122
try {
123123
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -164,7 +164,7 @@ except Exception as e:
164164
print(f'Error: {str(e)}', file=sys.stderr)
165165
sys.exit(1)
166166
"@
167-
$tempScript = Join-Path $env:TEMP "iceberg-to-parquet-$(Get-Random).py"
167+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "iceberg-to-parquet-$(Get-Random).py"
168168
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
169169
try {
170170
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1

profile.d/conversion-modules/data/binary/binary-protocol-orc.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ except Exception as e:
7575
print(f'Error: {str(e)}', file=sys.stderr)
7676
sys.exit(1)
7777
"@
78-
$tempScript = Join-Path $env:TEMP "orc-to-json-$(Get-Random).py"
78+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "orc-to-json-$(Get-Random).py"
7979
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
8080
try {
8181
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -140,7 +140,7 @@ except Exception as e:
140140
print(f'Error: {str(e)}', file=sys.stderr)
141141
sys.exit(1)
142142
"@
143-
$tempScript = Join-Path $env:TEMP "json-to-orc-$(Get-Random).py"
143+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "json-to-orc-$(Get-Random).py"
144144
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
145145
try {
146146
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -196,7 +196,7 @@ except Exception as e:
196196
print(f'Error: {str(e)}', file=sys.stderr)
197197
sys.exit(1)
198198
"@
199-
$tempScript = Join-Path $env:TEMP "orc-to-csv-$(Get-Random).py"
199+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "orc-to-csv-$(Get-Random).py"
200200
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
201201
try {
202202
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1
@@ -245,7 +245,7 @@ except Exception as e:
245245
print(f'Error: {str(e)}', file=sys.stderr)
246246
sys.exit(1)
247247
"@
248-
$tempScript = Join-Path $env:TEMP "orc-to-parquet-$(Get-Random).py"
248+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "orc-to-parquet-$(Get-Random).py"
249249
Set-Content -LiteralPath $tempScript -Value $pythonScript -Encoding UTF8
250250
try {
251251
$result = & $pythonCmd $tempScript $InputPath $OutputPath 2>&1

profile.d/conversion-modules/data/binary/binary-schema-avro.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ try {
5959
process.exit(1);
6060
}
6161
"@
62-
$tempScript = Join-Path $env:TEMP "avro-encode-$(Get-Random).js"
62+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "avro-encode-$(Get-Random).js"
6363
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
6464
try {
6565
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath
@@ -110,7 +110,7 @@ try {
110110
process.exit(1);
111111
}
112112
"@
113-
$tempScript = Join-Path $env:TEMP "avro-decode-$(Get-Random).js"
113+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "avro-decode-$(Get-Random).js"
114114
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
115115
try {
116116
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath
@@ -189,7 +189,7 @@ try {
189189
process.exit(1);
190190
}
191191
"@
192-
$tempScript = Join-Path $env:TEMP "avro-evolve-decode-$(Get-Random).js"
192+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "avro-evolve-decode-$(Get-Random).js"
193193
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
194194
try {
195195
$args = @($InputPath, $OutputPath)
@@ -265,7 +265,7 @@ try {
265265
process.exit(1);
266266
}
267267
"@
268-
$tempScript = Join-Path $env:TEMP "avro-compat-$(Get-Random).js"
268+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "avro-compat-$(Get-Random).js"
269269
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
270270
try {
271271
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $WriterSchemaPath, $ReaderSchemaPath

profile.d/conversion-modules/data/binary/binary-schema-flatbuffers.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ try {
6161
process.exit(1);
6262
}
6363
"@
64-
$tempScript = Join-Path $env:TEMP "flatbuffers-encode-$(Get-Random).js"
64+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "flatbuffers-encode-$(Get-Random).js"
6565
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
6666
try {
6767
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath
@@ -105,7 +105,7 @@ try {
105105
process.exit(1);
106106
}
107107
"@
108-
$tempScript = Join-Path $env:TEMP "flatbuffers-decode-$(Get-Random).js"
108+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "flatbuffers-decode-$(Get-Random).js"
109109
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
110110
try {
111111
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath

profile.d/conversion-modules/data/binary/binary-schema-protobuf.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ try {
6767
process.exit(1);
6868
}
6969
"@
70-
$tempScript = Join-Path $env:TEMP "protobuf-encode-$(Get-Random).js"
70+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "protobuf-encode-$(Get-Random).js"
7171
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
7272
try {
7373
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath
@@ -120,7 +120,7 @@ try {
120120
process.exit(1);
121121
}
122122
"@
123-
$tempScript = Join-Path $env:TEMP "protobuf-decode-$(Get-Random).js"
123+
$tempScript = Join-Path ([System.IO.Path]::GetTempPath()) "protobuf-decode-$(Get-Random).js"
124124
Set-Content -LiteralPath $tempScript -Value $nodeScript -Encoding UTF8
125125
try {
126126
$result = Invoke-NodeScript -ScriptPath $tempScript -Arguments $InputPath, $OutputPath, $SchemaPath

0 commit comments

Comments
 (0)