refactor: migrate all scripts and utils from bash to zsh (#3)
This commit is contained in:
@@ -7,23 +7,23 @@ Personal [Raycast](https://raycast.com) script collection.
|
|||||||
```
|
```
|
||||||
scripts/ # Raycast script commands
|
scripts/ # Raycast script commands
|
||||||
envs/ # Per-script .env files (gitignored)
|
envs/ # Per-script .env files (gitignored)
|
||||||
utils.sh # Shared helper: load_env
|
utils.zsh # Shared helper: load_env
|
||||||
```
|
```
|
||||||
|
|
||||||
## Scripts
|
## Scripts
|
||||||
|
|
||||||
| Script | Icon | Description |
|
| Script | Icon | Description |
|
||||||
| -------------------- | ---- | ------------------------------------------------------ |
|
| --------------------- | ---- | ------------------------------------------------------ |
|
||||||
| `base64.sh` | 🔡 | Encode/decode base64 — text, file path, or clipboard |
|
| `base64.zsh` | 🔡 | Encode/decode base64 — text, file path, or clipboard |
|
||||||
| `get_graph_user.sh` | 👤 | Fetch MS Graph user info by ID or UPN |
|
| `get_graph_user.zsh` | 👤 | Fetch MS Graph user info by ID or UPN |
|
||||||
| `imgflip-meme.sh` | 🖼️ | Generate a meme via imgflip webhook, copy to clipboard |
|
| `imgflip-meme.zsh` | 🖼️ | Generate a meme via imgflip webhook, copy to clipboard |
|
||||||
| `ipv4-get.sh` | 🌐 | Copy public IPv4 to clipboard |
|
| `ipv4-get.zsh` | 🌐 | Copy public IPv4 to clipboard |
|
||||||
| `no-as-a-service.sh` | ❌ | Random rejection reason from No-as-a-Service |
|
| `no-as-a-service.zsh` | ❌ | Random rejection reason from No-as-a-Service |
|
||||||
| `x.sh` | 🤖 | Copy Bruno ✕ character to clipboard |
|
| `x.zsh` | 🤖 | Copy Bruno ✕ character to clipboard |
|
||||||
|
|
||||||
## Environment files
|
## Environment files
|
||||||
|
|
||||||
Scripts that need secrets use `load_env` from `utils.sh`. Each script auto-loads `envs/<script-name>.env` at runtime.
|
Scripts that need secrets use `load_env` from `utils.zsh`. Each script auto-loads `envs/<script-name>.env` at runtime.
|
||||||
|
|
||||||
**Example** — `envs/get_graph_user.env`:
|
**Example** — `envs/get_graph_user.env`:
|
||||||
|
|
||||||
@@ -44,10 +44,10 @@ N8N_WEBHOOK_IMGFLIP_API_KEY="..."
|
|||||||
|
|
||||||
## Adding a new script
|
## Adding a new script
|
||||||
|
|
||||||
1. Create `scripts/my-script.sh` with Raycast metadata headers.
|
1. Create `scripts/my-script.zsh` with Raycast metadata headers.
|
||||||
2. Source the helper and call `load_env`:
|
2. Source the helper and call `load_env`:
|
||||||
```bash
|
```bash
|
||||||
source "$HOME/Raycast/utils.sh"
|
source "$HOME/Raycast/utils.zsh"
|
||||||
load_env VAR1 VAR2 || exit 1
|
load_env VAR1 VAR2 || exit 1
|
||||||
```
|
```
|
||||||
3. Create the matching `envs/my-script.env` with the required variables.
|
3. Create the matching `envs/my-script.env` with the required variables.
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
# Each script that needs to use the environment variables should have a env file with the same name as the script
|
# Each script that needs to use the environment variables should have a env file with the same name as the script
|
||||||
# For example, if you have a script called `train.sh`, you should create a file called `train.env`.
|
# For example, if you have a script called `train.zsh`, you should create a file called `train.env`.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# @raycast.schemaVersion 1
|
# @raycast.schemaVersion 1
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# @raycast.schemaVersion 1
|
# @raycast.schemaVersion 1
|
||||||
# @raycast.title Get Graph User
|
# @raycast.title Get Graph User
|
||||||
# @raycast.mode silent
|
# @raycast.mode compact
|
||||||
# @raycast.argument1 { "type": "text", "placeholder": "User ID or UPN" }
|
# @raycast.argument1 { "type": "text", "placeholder": "User ID or UPN" }
|
||||||
|
|
||||||
# Optional parameters:
|
# Optional parameters:
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
USER_ID="$1"
|
USER_ID="$1"
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source "$HOME/Raycast/utils.sh"
|
source "$HOME/Raycast/utils.zsh"
|
||||||
load_env AZURE_TENANT_ID AZURE_CLIENT_ID AZURE_CLIENT_SECRET || exit 1
|
load_env AZURE_TENANT_ID AZURE_CLIENT_ID AZURE_CLIENT_SECRET || exit 1
|
||||||
|
|
||||||
TOKEN_RESPONSE=$(curl -s -w "\n%{http_code}" \
|
TOKEN_RESPONSE=$(curl -s -w "\n%{http_code}" \
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# @raycast.schemaVersion 1
|
# @raycast.schemaVersion 1
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
# @raycast.author Esteban Vincent
|
# @raycast.author Esteban Vincent
|
||||||
|
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source "$HOME/Raycast/utils.sh"
|
source "$HOME/Raycast/utils.zsh"
|
||||||
load_env N8N_WEBHOOK_BASE_URL N8N_WEBHOOK_IMGFLIP_API_KEY || exit 1
|
load_env N8N_WEBHOOK_BASE_URL N8N_WEBHOOK_IMGFLIP_API_KEY || exit 1
|
||||||
|
|
||||||
QUERY="$1"
|
QUERY="$1"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# @raycast.schemaVersion 1
|
# @raycast.schemaVersion 1
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# @raycast.schemaVersion 1
|
# @raycast.schemaVersion 1
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
|
|
||||||
# Required parameters:
|
# Required parameters:
|
||||||
# @raycast.schemaVersion 1
|
# @raycast.schemaVersion 1
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/zsh
|
||||||
# Helper: source this file, then call load_env
|
# Helper: source this file, then call load_env
|
||||||
# Usage: source "$HOME/Raycast/utils/load_env.sh"
|
# Usage: source "$HOME/Raycast/utils/load_env.sh"
|
||||||
# load_env VAR1 VAR2 VAR3 || exit 1
|
# load_env VAR1 VAR2 VAR3 || exit 1
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
load_env() {
|
load_env() {
|
||||||
local caller
|
local caller
|
||||||
caller="$(basename "${BASH_SOURCE[1]}" .sh)"
|
caller="$(basename "${funcfiletrace[1]%:*}" .zsh)"
|
||||||
LOADED_ENV_FILE="$HOME/Raycast/envs/${caller}.env"
|
LOADED_ENV_FILE="$HOME/Raycast/envs/${caller}.env"
|
||||||
|
|
||||||
if [[ ! -f "$LOADED_ENV_FILE" ]]; then
|
if [[ ! -f "$LOADED_ENV_FILE" ]]; then
|
||||||
@@ -27,15 +27,15 @@ load_env() {
|
|||||||
if [[ "$value" == \"*\" ]]; then
|
if [[ "$value" == \"*\" ]]; then
|
||||||
value="${value#\"}"
|
value="${value#\"}"
|
||||||
value="${value%\"}"
|
value="${value%\"}"
|
||||||
elif [[ "$value" == \'*\' ]]; then
|
elif [[ "$value" == "'"*"'" ]]; then
|
||||||
value="${value#\'}"
|
value="${value#"'"}"
|
||||||
value="${value%\'}"
|
value="${value%"'"}"
|
||||||
fi
|
fi
|
||||||
export "$key=$value"
|
export "$key=$value"
|
||||||
done < "$LOADED_ENV_FILE"
|
done < "$LOADED_ENV_FILE"
|
||||||
|
|
||||||
for var in "$@"; do
|
for var in "$@"; do
|
||||||
if [[ -z "${!var}" ]]; then
|
if [[ -z "${(P)var}" ]]; then
|
||||||
echo "❌ Missing $var in .env"
|
echo "❌ Missing $var in .env"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
Reference in New Issue
Block a user