-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpashua.tcl
61 lines (51 loc) · 1.41 KB
/
pashua.tcl
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
# Tries to find the filesystem path to the executable
# in the Pashua.app application bundle
proc find_pashua {{path ""}} {
upvar #0 argv0 appName
upvar #0 env envir
set bundlePath "Pashua.app/Contents/MacOS/Pashua"
set homeDir $envir(HOME)
set theList [list "$appName/Pashua" \
"$appName/$bundlePath" \
"/$bundlePath" \
"[file dirname [info script]]/Pashua" \
"[file dirname [info script]]/$bundlePath" \
"./$bundlePath" \
"/Applications/$bundlePath" \
"$homeDir/Applications/$bundlePath" ]
if {$path != ""} {
# Prepend $path to the list of search paths
set theList [linsert $theList 0 "$path/$bundlePath"]
}
set theBinary ""
foreach possib $theList {
if {[file exists $possib]} then {
if {[file executable $possib]} then {
return $possib
}
}
}
return ""
}
# Displays a Pashua dialog with the given configuration
proc pashua_run {script {path ""}} {
set tempFile [exec /usr/bin/mktemp /tmp/Pashua_XXXXXXXX]
set handle [open $tempFile w]
puts $handle $script
close $handle
set theBinary [find_pashua $path]
if {$theBinary != ""} {
set handle [open "|\"$theBinary\" $tempFile" r]
while {[eof $handle]==0} {
gets $handle theLine
set equals [string first {=} $theLine]
if {$equals > -1} {
array set results \
[list [string range $theLine 0 [expr $equals - 1]] \
[string range $theLine [expr $equals + 1] end]]
}
}
return [array get results]
}
return ""
}