Skip to main content

Initial commit

ID
7b3d66c
date
2024-04-09 09:13:57+00:00
author
Alex Chan <alex@alexwlchan.net>
message
Initial commit
changed files
5 files, 110 additions

Changed files

.gitignore (0) → .gitignore (17)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a9e16d8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.alfredsnippets

LICENSE (0) → LICENSE (1053)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..b3d4b83
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2024 Alex Chan
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.

README.md (0) → README.md (447)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..af64a43
--- /dev/null
+++ b/README.md
@@ -0,0 +1,17 @@
+# alfred_snippets
+
+This is a simple script for creating my Alfred Snippet collections.
+
+## Usage
+
+```console
+$ python3 create_snippets.py
+```
+
+Then open the created `.alfredsnippets` files.
+
+## Notes
+
+It's possible to import Text Replacements in macOS Settings, and they sync to iOS devices.
+The behaviour is slightly different: you have to keep typing to accept the suggestion, rather than having it auto-expand.
+But might be worth checking out!

create_snippets.py (0) → create_snippets.py (1613)

diff --git a/create_snippets.py b/create_snippets.py
new file mode 100755
index 0000000..8375ff7
--- /dev/null
+++ b/create_snippets.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+
+import hashlib
+import json
+import os
+import pathlib
+import subprocess
+import uuid
+import zipfile
+
+
+# fmt: off
+SNIPPETS = {
+    # =========================
+    # English words and phrases
+    # =========================
+    "ina11e": "inaccessible",
+
+    # =============
+    # Personal info
+    # =============
+    "@aa": "@alexwlchan.net",
+    ";ee": "alex@alexwlchan.net",
+
+    ";ale": "alexwlchan",
+
+    # =================================
+    # Programming: shebangs for scripts
+    # =================================
+    "!bash": "#!/usr/bin/env bash\n\nset -o errexit\nset -o nounset\n",
+    "!osa": "#!/usr/bin/env osascript\n",
+    "!py": "#!/usr/bin/env python3\n\n",
+    "!rb": "#!/usr/bin/env ruby\n",
+    "!swift": "#!/usr/bin/env swift\n",
+}
+# fmt: on
+
+
+if __name__ == "__main__":
+    curdir = pathlib.Path(os.getcwd()).absolute()
+
+    with zipfile.ZipFile(f"Alex’s snippets.alfredsnippets", "w") as zf:
+        zf.write("info.plist")
+
+        for shortcut, expansion in SNIPPETS.items():
+            h = hashlib.md5()
+            h.update(shortcut.encode("utf8"))
+            h.update(expansion.encode("utf8"))
+
+            snippet_id = uuid.UUID(hex=h.hexdigest())
+
+            snippet_data = {
+                "alfredsnippet": {
+                    "snippet": expansion,
+                    "uid": str(snippet_id),
+                    "name": "",
+                    "keyword": shortcut,
+                }
+            }
+
+            zf.writestr(f"{snippet_id}.json", data=json.dumps(snippet_data))
+
+    subprocess.check_call(["open", "Alex’s snippets.alfredsnippets"])

info.plist (0) → info.plist (292)

diff --git a/info.plist b/info.plist
new file mode 100644
index 0000000..bb29003
--- /dev/null
+++ b/info.plist
@@ -0,0 +1,10 @@
+<?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>