Skip to content

Instantly share code, notes, and snippets.

@garyhtou
Last active April 1, 2022 18:00
Show Gist options
  • Save garyhtou/a3be116fe67b6c2714634a5586efe068 to your computer and use it in GitHub Desktop.
Save garyhtou/a3be116fe67b6c2714634a5586efe068 to your computer and use it in GitHub Desktop.
Raycast script for opening Heroku Rails Console

Raycast script for opening Heroku Rail Console

optimized for Hack Club Bank

Screen.Recording.2022-01-14.at.6.19.15.PM.mov

Installation

  1. Install Raycast if you don't already have it
  2. Download the bash script below
  3. Follow Raycast's Script Command install (instructions)

Usage

After installing, this script command can be found by searching for "Heroku Rails Console" (or it's acronym: hrc) in Raycast. PLEASE BE CAREFUL you can easily mess up production data with the Rails Console. This only makes it easier to do that 😁!

Shorthands

Shorthand Full Dyno Name
bank bank-hackclub
.PR_ID
^ notice the .
bank--pr-PR_ID (.1234 opens bank--pr-1234)

Things to know

  1. I use iTerm2, so it'll open in iTerm2 (it should be easy to switch it out for another terminal. Just replace iTerm2 in the apple script section)
  2. iTerm2 must already be running in the background
  3. You might need to give Raycast permission to open iTerm2 (Mac OS will prompt you during the initial run)
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Heroku Rails Console
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 💸
# @raycast.argument1 { "type": "text", "placeholder": "Dyno Name" }
# @raycast.packageName Heroku Run Rails Console
# Documentation:
# @raycast.description Heroku Run Rails Console
# @raycast.author Gary Tou
# @raycast.authorURL https://github.com/garyhtou
# Shorthands:
# .1234 will open PR #1234's deployment (bank--pr-1234)
# bank will open the Production deployment (bank-hackclub) with a confirmation prompt
# NOTE: Unfortunately iTerm2 must already be running. Also, you may have to give Raycast permission to open iTerm2 on first run
dyno_name=$1
# Verify that dyno_name argument exists
if [[ -z "$dyno_name" ]]; then
echo "\"Dyno Name\" is required"
exit 1
fi
# Substitute shorthands
if [[ $dyno_name = "bank" ]]; then
dyno_name="bank-hackclub"
elif [[ "$dyno_name" =~ ^\.([[:digit:]]+)$ ]]; then
dyno_name="bank--pr-${BASH_REMATCH[1]}"
fi
echo "Opening Heroku Dyno \"$dyno_name\""
# Defaults to iTerm2, this can be changed to another terminal such as "Terminal" (default Mac OS Terminal.app)
osascript -e "
tell application \"iTerm2\"
set newWindow to (create window with default profile)
tell current session of newWindow
write text \"heroku run rails c -a $dyno_name;\"
end tell
end tell
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment