-
Notifications
You must be signed in to change notification settings - Fork 2
/
r.sh
executable file
·162 lines (134 loc) · 5.6 KB
/
r.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
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
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env zsh
# shellcheck shell=bash
build:licenses () { #: Get all the licenses from pubspec.lock
cat LICENSE > workflow/LICENSES
echo "\n\n----------\n" >> workflow/LICENSES
dart-pubspec-licenses-lite -i pubspec.lock | grep -v null >> workflow/LICENSES
}
build:dart () { #: Build the version for the current architecture
dart compile exe bin/noteplan.dart -o "workflow/noteplan-$(uname -m)"
}
build:dart-local () { #: Build the version in the version controlled space
dart compile exe bin/noteplan.dart -o "bin-cache/noteplan-$(uname -m)"
}
build:icons () { #: Build the icns file from iconsets
mkdir workflow/icons
rm workflow/icons/*.icns
mkdir icons/iconsets
rm -fr icons/iconsets/**
# shellcheck disable=all
for I (create folder note daily weekly monthly quarterly yearly hyperlink code-bit); do
mkdir icons/iconsets/icon-$I.iconset
cp icons/ps-export/icon-$I-16.png icons/iconsets/icon-$I.iconset/icon_16x16.png
cp icons/ps-export/icon-$I-32.png icons/iconsets/icon-$I.iconset/[email protected]
cp icons/ps-export/icon-$I-32.png icons/iconsets/icon-$I.iconset/icon_32x32.png
cp icons/ps-export/icon-$I-64.png icons/iconsets/icon-$I.iconset/[email protected]
cp icons/ps-export/icon-$I-128.png icons/iconsets/icon-$I.iconset/icon_128x128.png
cp icons/ps-export/icon-$I-256.png icons/iconsets/icon-$I.iconset/[email protected]
cp icons/ps-export/icon-$I-256.png icons/iconsets/icon-$I.iconset/icon_256x256.png
convert icons/ps-export/icon-$I-1024.png -resize 50% icons/iconsets/icon-$I.iconset/[email protected]
convert icons/ps-export/icon-$I-1024.png -resize 50% icons/iconsets/icon-$I.iconset/icon_512x512.png
cp icons/ps-export/icon-$I-1024.png icons/iconsets/icon-$I.iconset/[email protected]
iconutil --convert icns icons/iconsets/icon-$I.iconset
done
mv icons/iconsets/*.icns workflow/icons
}
build:plistcheck () { #: dumps the objects "prebuild" tries update with scripts in test/workflow-*.sh
# should return:
# "Full-text search for Noteplan" in line 1
# "Opens exact Calendar note" in line 2
# "Find a URL you've saved in your notes"
# "Find and paste a code bit from your notes"
ERROR=0
[[
$(/usr/libexec/PlistBuddy -c "Print :objects:1:config:subtext" workflow/info.plist)
== "Full-text search for Noteplan"
]] || ERROR=1
[[
$(/usr/libexec/PlistBuddy -c "Print :objects:3:config:subtext" workflow/info.plist)
== "Opens exact Calendar note"
]] || ERROR=1
[[
$(/usr/libexec/PlistBuddy -c "Print :objects:6:config:subtext" workflow/info.plist)
== "Find a URL you've saved in your notes"
]] || ERROR=1
[[
$(/usr/libexec/PlistBuddy -c "Print :objects:8:config:subtext" workflow/info.plist)
== "Find and paste a code bit from your notes"
]] || ERROR=1
if (( $ERROR == 1 )); then
echo "workflow/info.plist: text doesn't match. Exiting…"
exit 1
fi
}
build:script () { #: Copy the script part from the workflow.sh into info.plist
cp workflow/info.plist workflow/info.plist.bak
SCRIPT=`cat test/workflow-search-all.sh | sed -E 's/(["'\''])/\\\\\1/g'`
/usr/libexec/PlistBuddy -c "Set :objects:1:config:script $SCRIPT" workflow/info.plist
SCRIPT=`cat test/workflow-date.sh | sed -E 's/(["'\''])/\\\\\1/g'`
/usr/libexec/PlistBuddy -c "Set :objects:3:config:script $SCRIPT" workflow/info.plist
SCRIPT=`cat test/workflow-search-hyperlinks.sh | sed -E 's/(["'\''])/\\\\\1/g'`
/usr/libexec/PlistBuddy -c "Set :objects:6:config:script $SCRIPT" workflow/info.plist
SCRIPT=`cat test/workflow-search-code-bits.sh | sed -E 's/(["'\''])/\\\\\1/g'`
/usr/libexec/PlistBuddy -c "Set :objects:8:config:script $SCRIPT" workflow/info.plist
}
build:workflow () { #: Zip the workflow folder into release/dist folder
cd workflow
VERSION=`/usr/libexec/PlistBuddy -c "Print :version" info.plist`
BUILD=`git rev-parse --short HEAD`
zip -r "../alfred-noteplan-$VERSION-$BUILD.alfredworkflow" icons/ info.plist icon.png LICENSES noteplan-arm64 noteplan-x86_64
}
prebuild () { #: Run the whole build - the local part
# build:icons
build:dart-local
build:plistcheck
build:script
}
build () { #: Run the build and packaging - on the runner
build:dart
cp bin-cache/noteplan-arm64 workflow/ # GA doesn't run on arm64 arch
build:licenses
build:workflow
}
version () { #: get the workflow version
defaults read "$(pwd)/workflow/info" version
}
dev:link () { #: link the WIP version to Alfred
ln -s \
/Users/adam/Code/alfred-noteplan/workflow \
/Users/adam/Code/dotfiles/config/alfred5/Alfred.alfredpreferences/workflows/alfred-noteplan;
}
dev:unlink () { #: remove the WIP version link from Alfred
rm /Users/adam/Code/dotfiles/config/alfred5/Alfred.alfredpreferences/workflows/alfred-noteplan;
}
dev:plisttest () { #: list all the object to search for the trigger notes
for i in {0..15}; do
echo -n "$i - "
/usr/libexec/PlistBuddy -c "Print :objects:${i}:config:subtext" workflow/info.plist
done
}
test () { #: run tests
zsh test/test.sh
}
#
# BOILERPLATE
#
r='./r.sh'
NAME='alfred-noteplan'
about () { #: show help & commands
echo "$NAME script runner"
echo "Commands:"
sed -nr 's/^(.*) \(\).* #: (.*)$/ \1 \2/p' $r | expand -20
}
if [[ $# -gt 0 ]]; then
command="$1"
shift 1
if type "$command" 2>/dev/null | grep -q 'function'; then
$command "$@"
else
about
echo "No command '$command'."
fi;
else
about
fi