| 1 |
|
| 2 |
# Tries to find the Pashua executable in one of a few default search locations or in |
| 3 |
# a custom path passed as optional argument. When it can be found, the filesystem |
| 4 |
# path will be in $pashuapath, otherwise $pashuapath will be empty. The return value |
| 5 |
# is 0 if it can be found, 1 otherwise. |
| 6 |
# |
| 7 |
# Argument 1: Path to a folder containing Pashua.app (optional) |
| 8 |
locate_pashua() { |
| 9 |
|
| 10 |
local bundlepath="Pashua.app/Contents/MacOS/Pashua" |
| 11 |
local mypath=`dirname "$0"` |
| 12 |
|
| 13 |
pashuapath="" |
| 14 |
|
| 15 |
if [ ! "$1" = "" ] |
| 16 |
then |
| 17 |
searchpaths[0]="$1/$bundlepath" |
| 18 |
fi |
| 19 |
searchpaths[1]="$mypath/Pashua" |
| 20 |
searchpaths[2]="$mypath/$bundlepath" |
| 21 |
searchpaths[3]="./$bundlepath" |
| 22 |
searchpaths[4]="/Applications/$bundlepath" |
| 23 |
searchpaths[5]="$HOME/Applications/$bundlepath" |
| 24 |
|
| 25 |
for searchpath in "${searchpaths[@]}" |
| 26 |
do |
| 27 |
if [ -f "$searchpath" -a -x "$searchpath" ] |
| 28 |
then |
| 29 |
pashuapath=$searchpath |
| 30 |
return 0 |
| 31 |
fi |
| 32 |
done |
| 33 |
|
| 34 |
return 1 |
| 35 |
} |
| 36 |
|
| 37 |
# Function for communicating with Pashua |
| 38 |
# |
| 39 |
# Argument 1: Configuration string |
| 40 |
# Argument 2: Path to a folder containing Pashua.app (optional) |
| 41 |
pashua_run() { |
| 42 |
|
| 43 |
# Write config file |
| 44 |
local pashua_configfile=`/usr/bin/mktemp /tmp/pashua_XXXXXXXXX` |
| 45 |
echo "$1" > "$pashua_configfile" |
| 46 |
|
| 47 |
locate_pashua "$2" |
| 48 |
|
| 49 |
if [ "" = "$pashuapath" ] |
| 50 |
then |
| 51 |
>&2 echo "Error: Pashua could not be found" |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
# Get result |
| 56 |
local result=$("$pashuapath" "$pashua_configfile") |
| 57 |
|
| 58 |
# Remove config file |
| 59 |
rm "$pashua_configfile" |
| 60 |
|
| 61 |
oldIFS="$IFS" |
| 62 |
IFS=$'\n' |
| 63 |
|
| 64 |
# Parse result |
| 65 |
for line in $result |
| 66 |
do |
| 67 |
local name=$(echo $line | sed 's/^\([^=]*\)=.*$/\1/') |
| 68 |
local value=$(echo $line | sed 's/^[^=]*=\(.*\)$/\1/') |
| 69 |
eval $name='$value' |
| 70 |
done |
| 71 |
|
| 72 |
IFS="$oldIFS" |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
function pash { |
| 78 |
location='' |
| 79 |
locate_pashua "$location" |
| 80 |
pashua_run "$conf" "$location" 2>/dev/null |
| 81 |
} |
| 82 |
|
| 83 |
function _escape_newline { |
| 84 |
text=${text//$'\n'/[return]} |
| 85 |
} |
| 86 |
|
| 87 |
_escape_newline |
| 88 |
|
| 89 |
|
| 90 |
function password { |
| 91 |
conf=" |
| 92 |
*.title="$title" |
| 93 |
*.floating=1 |
| 94 |
*.autoclosetime="$timeout" |
| 95 |
tx.type=text |
| 96 |
tx.default="$text" |
| 97 |
pw.type=password |
| 98 |
pw.label="$label" |
| 99 |
pw.default="$init" |
| 100 |
cb.type=cancelbutton |
| 101 |
" |
| 102 |
pash |
| 103 |
if [ ! -z "$pw" ]; then |
| 104 |
echo "$pw" |
| 105 |
fi |
| 106 |
exit $cb |
| 107 |
} |
| 108 |
|
| 109 |
function input { |
| 110 |
conf=" |
| 111 |
*.title="$title" |
| 112 |
*.floating=1 |
| 113 |
*.autoclosetime="$timeout" |
| 114 |
txt.type=text |
| 115 |
txt.default="$text" |
| 116 |
tx.type=textfield |
| 117 |
tx.label="$label" |
| 118 |
tx.default="$init" |
| 119 |
cb.type=cancelbutton |
| 120 |
" |
| 121 |
pash |
| 122 |
if [ ! -z "$tx" ]; then |
| 123 |
echo "$tx" |
| 124 |
fi |
| 125 |
exit $cb |
| 126 |
} |
| 127 |
|
| 128 |
function confirm_default_no { |
| 129 |
conf=" |
| 130 |
*.title="$title" |
| 131 |
*.floating=1 |
| 132 |
*.autoclosetime="$timeout" |
| 133 |
txt.type=text |
| 134 |
txt.default="$text" |
| 135 |
ok.type=defaultbutton |
| 136 |
ok.label=No |
| 137 |
cb.type=cancelbutton |
| 138 |
cb.label=Yes |
| 139 |
" |
| 140 |
pash |
| 141 |
if [ $cb != 0 ]; then |
| 142 |
echo "yes" |
| 143 |
exit 0 |
| 144 |
else |
| 145 |
exit 1 |
| 146 |
fi |
| 147 |
} |
| 148 |
|
| 149 |
function confirm_default_yes { |
| 150 |
conf=" |
| 151 |
*.title="$title" |
| 152 |
*.floating=1 |
| 153 |
*.autoclosetime="$timeout" |
| 154 |
txt.type=text |
| 155 |
txt.default="$text" |
| 156 |
ok.type=defaultbutton |
| 157 |
ok.label=Yes |
| 158 |
cb.type=cancelbutton |
| 159 |
cb.label=No |
| 160 |
" |
| 161 |
pash |
| 162 |
if [ $cb == 0 ]; then |
| 163 |
echo "yes" |
| 164 |
fi |
| 165 |
exit $cb |
| 166 |
} |
| 167 |
|
| 168 |
function _select { |
| 169 |
conf=" |
| 170 |
*.title="$title" |
| 171 |
*.floating=1 |
| 172 |
*.autoclosetime="$timeout" |
| 173 |
txt.type=text |
| 174 |
txt.default="$text" |
| 175 |
tx.type=popup |
| 176 |
tx.label="$label" |
| 177 |
tx.default="$init" |
| 178 |
tx.option="$init" |
| 179 |
cb.type=cancelbutton |
| 180 |
" |
| 181 |
for opt in "${@}"; do |
| 182 |
conf+="tx.option="$opt" |
| 183 |
" |
| 184 |
done |
| 185 |
pash |
| 186 |
if [ ! -z "$tx" ]; then |
| 187 |
echo "$tx" |
| 188 |
fi |
| 189 |
exit $cb |
| 190 |
} |
| 191 |
|
| 192 |
function _select_other { |
| 193 |
conf=" |
| 194 |
*.title="$title" |
| 195 |
*.floating=1 |
| 196 |
*.autoclosetime="$timeout" |
| 197 |
txt.type=text |
| 198 |
txt.default="$text" |
| 199 |
tx.type=combobox |
| 200 |
tx.completion=2 |
| 201 |
tx.label="$label" |
| 202 |
tx.default="$init" |
| 203 |
tx.option="$init" |
| 204 |
cb.type=cancelbutton |
| 205 |
" |
| 206 |
for opt in "${@}"; do |
| 207 |
conf+="tx.option="$opt" |
| 208 |
" |
| 209 |
done |
| 210 |
pash |
| 211 |
if [ ! -z "$tx" ]; then |
| 212 |
echo "$tx" |
| 213 |
fi |
| 214 |
exit $cb |
| 215 |
} |
| 216 |
|
| 217 |
function select2 { |
| 218 |
if [ "$type" == "select-other" ]; then |
| 219 |
_select_other ${@} |
| 220 |
else |
| 221 |
_select ${@} |
| 222 |
fi |
| 223 |
} |
| 224 |
|
| 225 |
function multiple { |
| 226 |
conf=" |
| 227 |
*.title="$title" |
| 228 |
*.floating=1 |
| 229 |
*.autoclosetime="$timeout" |
| 230 |
txt.type=text |
| 231 |
txt.default="$text" |
| 232 |
tx.type=textbox |
| 233 |
tx.height=104 |
| 234 |
tx.label="$label" |
| 235 |
tx.default="$(printf '%s[return]' "${@}")" |
| 236 |
cb.type=cancelbutton |
| 237 |
" |
| 238 |
pash |
| 239 |
if [ ! -z "$tx" ]; then |
| 240 |
echo "$(echo "$tx" | sed 's/\[return\]/\ |
| 241 |
/g' | grep -v '^$')" |
| 242 |
fi |
| 243 |
exit $cb |
| 244 |
} |
| 245 |
|
| 246 |
function simple_link_QR { |
| 247 |
conf=" |
| 248 |
*.title="$title" |
| 249 |
*.floating=1 |
| 250 |
*.autoclosetime="$timeout" |
| 251 |
txt.type=text |
| 252 |
txt.default="$text" |
| 253 |
img.type=image |
| 254 |
img.path="$init" |
| 255 |
" |
| 256 |
pash |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
function complex_link { |
| 261 |
conf=" |
| 262 |
*.title="$title" |
| 263 |
*.floating=1 |
| 264 |
*.autoclosetime="$timeout" |
| 265 |
txt.type=text |
| 266 |
txt.default="$text" |
| 267 |
" |
| 268 |
pash |
| 269 |
} |