From aa85bb0c72015ec6ac5156d71a15847acc14c6df Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Wed, 19 Feb 2025 10:13:52 +0200 Subject: [PATCH] feat(bin): raycast helpers Signed-off-by: Ismo Vuorinen --- local/bin/raycast/lungo-activate.sh | 22 +++++ local/bin/raycast/lungo-deactivate.sh | 20 +++++ local/bin/raycast/lungo-toggle.sh | 22 +++++ local/bin/raycast/markdown-to-telegram.py | 100 ++++++++++++++++++++++ local/bin/raycast/sp.sh | 21 +++++ local/bin/raycast/tidal.applescript | 26 ++++++ local/bin/raycast/zalgo-text.swift | 49 +++++++++++ 7 files changed, 260 insertions(+) create mode 100755 local/bin/raycast/lungo-activate.sh create mode 100755 local/bin/raycast/lungo-deactivate.sh create mode 100755 local/bin/raycast/lungo-toggle.sh create mode 100755 local/bin/raycast/markdown-to-telegram.py create mode 100755 local/bin/raycast/sp.sh create mode 100755 local/bin/raycast/tidal.applescript create mode 100755 local/bin/raycast/zalgo-text.swift diff --git a/local/bin/raycast/lungo-activate.sh b/local/bin/raycast/lungo-activate.sh new file mode 100755 index 0000000..3889f38 --- /dev/null +++ b/local/bin/raycast/lungo-activate.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Note: Lungo v2.0.4 required +# Install via Mac App Store: https://apps.apple.com/app/id1263070803 + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Lungo: Activate +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon ./images/lungo.png +# @raycast.packageName Lungo + +# Documentation: +# @raycast.author Lungo +# @raycast.authorURL https://sindresorhus.com/lungo +# @raycast.description Deactivate Lungo. +# @raycast.argument1 { "type": "text", "placeholder": "hours", "optional": true, "percentEncoded": true } +# @raycast.argument2 { "type": "text", "placeholder": "minutes", "optional": true, "percentEncoded": true } + +open --background "lungo:activate?hours=$1&minutes=$2" diff --git a/local/bin/raycast/lungo-deactivate.sh b/local/bin/raycast/lungo-deactivate.sh new file mode 100755 index 0000000..3e6f6a8 --- /dev/null +++ b/local/bin/raycast/lungo-deactivate.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Note: Lungo v2.0.4 required +# Install via Mac App Store: https://apps.apple.com/app/id1263070803 + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Lungo: Deactivate +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon ./images/lungo.png +# @raycast.packageName Lungo + +# Documentation: +# @raycast.author Lungo +# @raycast.authorURL https://sindresorhus.com/lungo +# @raycast.description Deactivate Lungo. + +open --background lungo:deactivate diff --git a/local/bin/raycast/lungo-toggle.sh b/local/bin/raycast/lungo-toggle.sh new file mode 100755 index 0000000..50b5716 --- /dev/null +++ b/local/bin/raycast/lungo-toggle.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Note: Lungo v2.0.4 required +# Install via Mac App Store: https://apps.apple.com/app/id1263070803 + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Lungo: Toggle +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon ./images/lungo.png +# @raycast.packageName Lungo + +# Documentation: +# @raycast.author Lungo +# @raycast.authorURL https://sindresorhus.com/lungo +# @raycast.description Toggle Lungo. +# @raycast.argument1 { "type": "text", "placeholder": "hours", "optional": true, "percentEncoded": true } +# @raycast.argument2 { "type": "text", "placeholder": "minutes", "optional": true, "percentEncoded": true } + +open --background "lungo:toggle?hours=$1&minutes=$2" diff --git a/local/bin/raycast/markdown-to-telegram.py b/local/bin/raycast/markdown-to-telegram.py new file mode 100755 index 0000000..78b138a --- /dev/null +++ b/local/bin/raycast/markdown-to-telegram.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python3 + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Convert Markdown to Telegram Format +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon 🔄 +# @raycast.packageName Conversions +# @raycast.description Convert Markdown formatting to Telegram format, excluding processing inside code blocks or quotes + +# Documentation: +# @raycast.author Maxim Borzov +# @raycast.authorURL https://github.com/borzov + +import re +import subprocess + +# Set environment variables and encoding +env_vars = {'LANG': 'en_US.UTF-8'} +encoding = 'utf-8' + +def paste(): + """Read text from the clipboard.""" + return subprocess.check_output('pbpaste', env=env_vars).decode(encoding) + +def copy(text): + """Write text to the clipboard.""" + process = subprocess.Popen('pbcopy', env=env_vars, stdin=subprocess.PIPE) + process.communicate(text.encode(encoding)) + +def convert_markdown(text): + """Convert Markdown formatting to Telegram format.""" + lines = text.split('\n') + converted_lines = [] + in_code_block = False + + for line in lines: + # Check if the line is a code block delimiter + if line.startswith('```'): + in_code_block = not in_code_block + converted_lines.append(line) + continue + + # Skip quotes and only format if not in a code block + if not in_code_block and not line.startswith('>'): + # Format headers with emojis and bold text + if line.startswith('# '): + line = f"⚫️ **{line[2:].strip()}**\n" + elif line.startswith('## '): + line = f"◾️ **{line[3:].strip()}**\n" + elif line.startswith('### '): + line = f"▪️ **{line[4:].strip()}**\n" + elif line.startswith('#### '): + line = f"🔹 **{line[5:].strip()}**\n" + elif line.startswith('##### '): + line = f"📌 **{line[6:].strip()}**\n" + elif line.startswith('###### '): + line = f"🔰 **{line[7:].strip()}**\n" + else: + # Format bold text + line = re.sub(r'(?')) and not next.startswith(('*', '-', '```', '|', '>')): + result.append('') + + return '\n'.join(result) + +if __name__ == "__main__": + try: + markdown_text = paste() + converted_text = convert_markdown(markdown_text) + copy(converted_text) + print("✅ Markdown converted and copied to clipboard") + except Exception as e: + print(f"❌ Error during conversion: {str(e)}") diff --git a/local/bin/raycast/sp.sh b/local/bin/raycast/sp.sh new file mode 100755 index 0000000..e48d996 --- /dev/null +++ b/local/bin/raycast/sp.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Dependency: requires the 1password cli: https://developer.1password.com/docs/cli/ + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Login password to clipboard +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon 🔐 +# @raycast.packageName Password to clipboard +# @raycast.description Returns password from 1Password + +# Documentation: +# @raycast.author Ismo Vuorinen +# @raycast.authorURL https://github.com/ivuorinen + +set -euo pipefail + +op read "op://Svea/3hzhctmvovbwlgulv7mgy25rf4/login-input" | pbcopy diff --git a/local/bin/raycast/tidal.applescript b/local/bin/raycast/tidal.applescript new file mode 100755 index 0000000..dc9a3c6 --- /dev/null +++ b/local/bin/raycast/tidal.applescript @@ -0,0 +1,26 @@ +#!/usr/bin/osascript + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Tidal: Toggle Play/Pause +# @raycast.mode silent +# @raycast.packagename Tidal + +# Optional parameters +# @raycast.icon images/tidal-logo.png + +# Documentation: +# @raycast.author Cebrail AKTAS +# @raycast.authorURL https://github.com/AktasC +# @raycast.description Play/Pause Tidal + +tell application "System Events" + tell process "TIDAL" + click first menu item of menu "Playback" of menu bar 1 + if name of first menu item of menu "Playback" of menu bar 1 is "Play" then + log "▶️" + else + log "⏸" + end if + end tell +end tell diff --git a/local/bin/raycast/zalgo-text.swift b/local/bin/raycast/zalgo-text.swift new file mode 100755 index 0000000..4e1e354 --- /dev/null +++ b/local/bin/raycast/zalgo-text.swift @@ -0,0 +1,49 @@ +#!/usr/bin/swift + +// Required parameters: +// @raycast.schemaVersion 1 +// @raycast.title Zalgo Text +// @raycast.mode silent +// @raycast.author Adam Zethraeus +// @raycast.authorURL https://github.com/adam-zethraeus +// @raycast.packageName Conversions +// @raycast.icon 👹 +// @raycast.argument1 { "type": "text", "placeholder": "Text to Z̶̶͚̯͗a̩̞͜͜l̫͕ͬͨ̿g͈̫͂ͤ͆͢o̠͚̞ͥ" } +// @raycast.argument2 { "type": "text", "optional": true, "placeholder": "Intensity=5" } + +// Documentation: +// @raycast.description Converts text to z̫̫̐a̳ͩl̓͂̀ͅg͔̚o̷̦̣͢ t̳͆ḛ̊͟ẍ̮̝́t̵̔ͯ͝ + +import Cocoa + +// zalgo function credit mattt @ https://gist.github.com/mattt/b46ab5027f1ee6ab1a45583a41240033 +func zalgo(_ string: String, intensity: Int = 5) -> String { + let combiningDiacriticMarks = 0x0300...0x036f + let latinAlphabetUppercase = 0x0041...0x005a + let latinAlphabetLowercase = 0x0061...0x007a + + var output: [UnicodeScalar] = [] + for scalar in string.unicodeScalars { + output.append(scalar) + guard (latinAlphabetUppercase).contains(numericCast(scalar.value)) || + (latinAlphabetLowercase).contains(numericCast(scalar.value)) + else { + continue + } + + for _ in 0...(Int.random(in: 1...intensity)) { + let randomScalarValue = Int.random(in: combiningDiacriticMarks) + output.append(Unicode.Scalar(randomScalarValue)!) + } + } + + return String(String.UnicodeScalarView(output)) +} + +NSPasteboard.general.clearContents() +let text = CommandLine.arguments[1] +let intensityString = CommandLine.arguments[2] +let intensity = Int(intensityString) ?? 5 +let zalgoText = zalgo(text, intensity: intensity) +NSPasteboard.general.setString(zalgoText, forType: .string) +print("\(zalgoText) copied to clipboard")