forked from BlueM/Pashua-Binding-Bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pashua.sh
executable file
·73 lines (58 loc) · 1.77 KB
/
pashua.sh
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
# Tries to find the Pashua executable in one of a few default search locations or in
# a custom path passed as optional argument. When it can be found, the filesystem
# path will be in $pashuapath, otherwise $pashuapath will be empty. The return value
# is 0 if it can be found, 1 otherwise.
#
# Argument 1: Path to a folder containing Pashua.app (optional)
locate_pashua() {
local bundlepath="Pashua.app/Contents/MacOS/Pashua"
local mypath=`dirname "$0"`
pashuapath=""
if [ ! "$1" = "" ]
then
searchpaths[0]="$1/$bundlepath"
fi
searchpaths[1]="$mypath/Pashua"
searchpaths[2]="$mypath/$bundlepath"
searchpaths[3]="./$bundlepath"
searchpaths[4]="/Applications/$bundlepath"
searchpaths[5]="$HOME/Applications/$bundlepath"
for searchpath in "${searchpaths[@]}"
do
if [ -f "$searchpath" -a -x "$searchpath" ]
then
pashuapath=$searchpath
return 0
fi
done
return 1
}
# Function for communicating with Pashua
#
# Argument 1: Configuration string
# Argument 2: Path to a folder containing Pashua.app (optional)
pashua_run() {
# Write config file
local pashua_configfile=`/usr/bin/mktemp "${TMPDIR:-/tmp}"/pashua_XXXXXXXXX`
echo "$1" > "$pashua_configfile"
locate_pashua "$2"
if [ "" = "$pashuapath" ]
then
>&2 echo "Error: Pashua could not be found"
exit 1
fi
# Get result
local result=$("$pashuapath" "$pashua_configfile")
# Remove config file
rm "$pashua_configfile"
oldIFS="$IFS"
IFS=$'\n'
# Parse result
for line in $result
do
local name=$(echo $line | sed 's/^\([^=]*\)=.*$/\1/')
local value=$(echo $line | sed 's/^[^=]*=\(.*\)$/\1/')
eval $name='$value'
done
IFS="$oldIFS"
}