Add a script to make the Alfred snippet
- ID
e059a5f- date
2024-07-14 14:48:45+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
8316eba- message
Add a script to make the Alfred snippet- changed files
1 file, 45 additions
Changed files
make_alfred_snippet.sh (0) → make_alfred_snippet.sh (1068)
diff --git a/make_alfred_snippet.sh b/make_alfred_snippet.sh
new file mode 100755
index 0000000..715aa5d
--- /dev/null
+++ b/make_alfred_snippet.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env bash
+# This script creates an Alfred snippet bundle that expands my HTML template
+# when I type the shortcut `!html`.
+
+set -o errexit
+set -o nounset
+
+KEYWORD="!html"
+
+ROOT=$(git rev-parse --show-toplevel)
+
+pushd $(mktemp -d)
+ cat > info.plist <<EOF
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>snippetkeywordprefix</key>
+ <string></string>
+ <key>snippetkeywordsuffix</key>
+ <string></string>
+</dict>
+</plist>
+EOF
+
+ # Get the HTML template as a JSON-escaped string
+ snippet=$(jq -R -s '.' < "$ROOT/index.html")
+
+ # This is an arbitrary choice of ID; it just has to be used consistently
+ snippet_id="$(uuidgen)"
+
+ cat > "$snippet_id.json" <<EOF
+{
+ "alfredsnippet": {
+ "snippet": $snippet,
+ "uid": "$snippet_id",
+ "name": "HTML template",
+ "keyword": "$KEYWORD"
+ }
+}
+EOF
+
+ zip "HTML template.alfredsnippets" "info.plist" "$snippet_id.json"
+ open "HTML template.alfredsnippets"
+popd