Skip to content

Instantly share code, notes, and snippets.

@kaveet
Created October 24, 2024 18:45
Show Gist options
  • Select an option

  • Save kaveet/caf539af3f6daa932ca39e0fb49a42a9 to your computer and use it in GitHub Desktop.

Select an option

Save kaveet/caf539af3f6daa932ca39e0fb49a42a9 to your computer and use it in GitHub Desktop.
A Raycast Script command to covert from a column of text to a comma-separated, single-quoted list.
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Column to Comma-Separated
# @raycast.description Converts a column of data into a comma-separated list with single quotes and copies it to the clipboard.
# @raycast.mode compact
# @raycast.packageName Conversions
# Optional parameters:
# @raycast.icon 🗂
# Read the clipboard contents
clipboard=$(pbpaste)
# Initialize an empty array to hold the quoted entries
quoted_entries=()
# Iterate over each line in the clipboard
while IFS= read -r line; do
# Skip empty lines to avoid adding empty quotes
if [[ -n "$line" ]]; then
quoted_entries+=("'$line'")
fi
done <<< "$clipboard"
# Join the quoted entries with commas
comma_separated=$(IFS=, ; echo "${quoted_entries[*]}")
echo "$comma_separated" | pbcopy
echo "✅ Contents have been copied to the clipboard."
@kaveet
Copy link
Copy Markdown
Author

kaveet commented Oct 24, 2024

How to use:

  1. Create a directory for your scripts ~/Raycast/scripts/
  2. Place the shell file in the directory
  3. Open the Raycast Extensions settings
  4. Select Scripts (Script Commands)
  5. Click Add Directories
  6. Select the scripts directory you added
  7. Copy data to the clipboard
  8. Run Column to Comma-Separated from Raycast
  9. Profit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment